如何使用jquery触发双击单击 [英] how to trigger a double click on a single click using jquery
问题描述
是否可以触发双击用户的单击?请注意,我想要使用鼠标双击相同的行为,是否可以使用jQuery获得相同的行为?目前为止我已经尝试过:
Is it possible to trigger double click on user's single click? note that I want the same behaviour as it was double clicked by using mouse, Is it possible to get the same behaviour using jQuery? What I've tried so far :
$("#container").dblclick(function() {
//code executed on jQuery double click rather than mouse double click
});
$("#container").click(function() {
$(this).dblclick();
});
当我双击鼠标时,它会正确的生成正确的结果,但是当我尝试用jQuery做它,似乎没有工作,请帮助!感谢提前:)
When I double click using mouse it goes right, it generate the right result I want, but when I try to do it with jQuery, it does not seem to be working, please Help! Thanks in Advance :)
推荐答案
不知道你的问题在哪里,但是这个代码的工作原理与预期的一样:
Not sure where exactly your problem is, but this code works exactly as expected:
$("#container").dblclick(function() {
//code executed on jQuery double click rather than mouse double click
alert('dblclick');
});
$("#container").click(function() {
alert('click');
$(this).dblclick();
});
$("#container2").click(function() {
$("#container").click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">click 1</div>
<div id="container2">click 2</div>
如果您点击点击1 - 您将有2个警报(原始和dblclick)。
如果您点击点击2 - jQuery将触发第一个元素上的点击
,将触发2个警报(单击
和 dblclick
)。
If you click on 'click 1' - you will have the 2 alerts (the original and the dblclick).
If you click on 'click 2' - the jquery will trigger the click
on the first element, which will trigger 2 alerts (the click
and the dblclick
).
这篇关于如何使用jquery触发双击单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!