最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Javascript onclick and ondblclick in same button - Stack Overflow

programmeradmin3浏览0评论

does anybody know an solution for buttons to react on 2 click events for only one button:

<input type="button" value="Click" ondblclick="alert('double')"; onclick="alert('ones')";>

@At my try if I double click on button, it alert only 'ones'; Why it isn't possible to have ondblclick and onclick in the same button?

does anybody know an solution for buttons to react on 2 click events for only one button:

<input type="button" value="Click" ondblclick="alert('double')"; onclick="alert('ones')";>

@At my try if I double click on button, it alert only 'ones'; Why it isn't possible to have ondblclick and onclick in the same button?

Share Improve this question edited Jun 30, 2015 at 15:06 Яраслаў Жук 537 bronze badges asked Sep 11, 2013 at 10:39 ButtersButters 1,0575 gold badges15 silver badges25 bronze badges 5
  • Is it something like you want to restrict the user from double-clicking? – Ganesh Pandhere Commented Sep 11, 2013 at 10:41
  • Then don't use alert which is modal and fired a blur event in most browsers – A. Wolff Commented Sep 11, 2013 at 10:41
  • why do you want such behavior doesnt look good to me – Prabhu Murthy Commented Sep 11, 2013 at 10:42
  • If you double click the button then alert('ones') will appear on your screen.What do you wants to do ? – Satyam Koyani Commented Sep 11, 2013 at 10:45
  • It is possible, but why would you want a double-click handler on a button element? It could make sense on a number of other elements (e.g., an option element within a (non drop-down) select element where one click selects and the second submits or something), but I've never needed to handle a double-click on a button. – nnnnnn Commented Sep 11, 2013 at 10:51
Add a ment  | 

2 Answers 2

Reset to default 6
<input type="button" value="Click" ondblclick="console.log('double');" onclick="console.log('ones')";>

Magically, it works!

Your problem is you are using alert() which is modal and so makes your ondblclick event impossible to be fired.

You an give timeout for click so that alert pops up bit slow..

<input type="button" value="Click" ondblclick="alert('double')"; onclick="setTimeout(function(){alert('ones')},3000);";>
发布评论

评论列表(0)

  1. 暂无评论