简体   繁体   English

Click事件触发两次,但仅在触摸设备上触发

[英]Click event fires twice, but only on touch devices

$('.classy').on('click', 'button', function(){
    console.log('clicked');
})

- --

<div class='classy'>
    <button> - </button>
</div>

Any reason why this would fire twice on a touch device? 有什么原因会在触摸设备上触发两次? It works perfectly with normal mouse events. 它与正常的鼠标事件完美配合。

note: I've also tried .bind .live just to make sure, same problem. 注意:我也尝试过.bind .live只是为了确保同样的问题。

Try passing the event and then invoking preventDefault(). 尝试传递事件,然后调用preventDefault()。

$('.classy').on('click', 'button', function(e){
e.preventDefault();
console.log('clicked');
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM