jQuery:内容之外的 Doubleckick
我的内容在主体中间宽度为 720px。我希望,如果人们在该内容之外双击鼠标即可使用 jQuery 执行功能。
我知道如何如果双击正文
,但这也包括内容,所以我想知道如何排除一些 div 和类。
多谢
I have a content with with a width of 720px in the middle of a body. I want, if people press doubleclick outside of that content to do function using jQuery.
I know how I could do the if double click on the body
but that includes the content aswell so I'd liked to know how can I exclude some div's and classes.
Thanks alot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需停止 dblclick 事件从内容到文档其余部分的传播:
这样,#content 元素上的任何双击事件都不会被其父元素接收。
因此,以下处理程序将不会接收双击内容元素的 dbclick 事件:
在此处尝试: http://jsfiddle.net /E4tZQ/
请参阅
event.stopPropagation()
文档。Simply stop the propagation of the dblclick event from the content to the rest of the document:
With this, any double click event on the #content element will not be received by any of its parent.
So the following handler will not receive dbclick events for double clicks on the content element:
Try it here: http://jsfiddle.net/E4tZQ/
See
event.stopPropagation()
documentation.您需要一种方法来测试双击,并在单击内容 div 时停止传播:
http://jsfiddle .net/STchX/
You need both a way to test for the double click, and to stop propagation when the content div is clicked:
http://jsfiddle.net/STchX/
您可以将另一个双击处理程序设置为内容容器(720px)
其中有 event.preventDefault() 并返回 false;
< a href="http://api.jquery.com/event.stopPropagation/" rel="nofollow">event.stopPropagation() 也可以。
You can set another doubleclick handler to the container of your content (720px)
which has event.preventDefault() inside and returns false;
event.stopPropagation() works too.