我正在学习JavaScript。 我注意到,如果我快速地多次点击一个对象,某些单击将被捕获为双击。在JavaScript中是否有可能将所有点击都捕获为单击?
我正在学习JavaScript。 我注意到,如果我快速地多次点击一个对象,某些单击将被捕获为双击。在JavaScript中是否有可能将所有点击都捕获为单击?
$(document).dblclick(function(e) {
e.preventDefault();
alert('Handler for .dblclick() called and ignored.');
});
双击示例可查看结果。
解决这个问题有两个选项。
1)在双击事件上使用“return false;”语句。 例如:
<button id="your button id" onclick="yourfuntion()" ondblclick="return false;" >My Button</button>
2) 在您的主函数开头禁用按钮/对象,在函数结束时再次启用它。
示例:
<button id="your button id" onclick="yourfuntion()">My Button</button>
<script>
function yourfuntion() { document.getElementById("your button id").disabled = true;
//your javascript code
document.getElementById("your button id").disabled = false;}
</script>
mouseDown
事件而不是click
事件。 - Kieren Johnstone