在点击事件中如何知道这是双击。如果是点击,我要返回;但如何知道这是双击呢?
<hr style="clear:both; width:100%;" />
<p id="testClick">Click here</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#testClick").click(function () {
//if double click: console.log("2"); and return
//else
// do some thing
console.log("1");
});
});
</script>
最佳答案
无法从单击处理程序中得知。您必须构建一个自定义逻辑,如下答案所示:how to detect a double on a single click in jquery
我建议你听听这两个事件并围绕它建立你的逻辑。如果您只需要了解双击,就不要听单击。
使用dblclick事件处理程序:
<hr style="clear:both; width:100%;" />
<p id="testClick">Click here</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#testClick").click(function () {
console.log("click"); // Here do nothing !
});
$("#testClick").dblclick(function () {
console.log("double click");
});
});
</script>
关于javascript - 如何在 jquery 中检测一次单击的双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47935150/