Javascript 双击触发的单击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7119838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Single click triggered on a double click
提问by Xavier
Possible Duplicate:
Need to cancel click/mouseup events when double-click event detected
I am trying to get a HTML object to behave differently when a single
or double
click event happens.
我试图让 HTML 对象在发生single
或double
单击事件时表现不同。
Currently with my working example http://jsfiddle.net/9vvEG/the single click is triggered on the double click, I wish for my code to listen exclusively for the event pre-configured. i.e. if double clicked ignore single click and vice versa.
目前,在我的工作示例http://jsfiddle.net/9vvEG/ 中,单击是在双击时触发的,我希望我的代码专门监听预先配置的事件。 即如果双击忽略单击,反之亦然。
No success as of yet, but if you click my example link above you can see the error in progress.
到目前为止还没有成功,但是如果您单击我上面的示例链接,您可以看到正在进行的错误。
采纳答案by Naveed
I think you have to note the time between two clicks using setTimeout. Look a solution here:
我认为您必须使用 setTimeout 记录两次单击之间的时间。看看这里的解决方案:
This may also help you:
这也可以帮助您:
回答by James Allardice
From the jQuery docs on dblclick
:
来自 jQuery 文档dblclick
:
It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.
不建议将处理程序绑定到同一元素的 click 和 dblclick 事件。触发事件的顺序因浏览器而异,有些在 dblclick 之前收到两个点击事件,而其他只收到一个。双击灵敏度(被检测为双击的最大单击间隔时间)可能因操作系统和浏览器而异,并且通常是用户可配置的。
It seems that there is going to be no reliable way to determine whether the user intended a double click or two single clicks, but if you want to try, you could perhaps use setTimeout
in a click
event handler to see if another click occurs within a certain period of time.
似乎没有可靠的方法来确定用户是想要双击还是两次单击,但是如果您想尝试,您可以setTimeout
在click
事件处理程序中使用以查看在特定时间段内是否发生了另一次点击时间。