如何打开/关闭 $(document).click() 事件或其他解决方案
我有一个 DIV 标签,单击该标签时我想启动一个进程,然后单击文档上的任意位置我想结束该进程。到目前为止,我已经尝试过:
$(document).click(end_process);
$('div_tag_id').click(start_process);
这不好,因为单击启动进程也会立即结束进程。有什么想法吗?
I have a DIV tag which when clicked I want to start a process, after which clicking anywhere on the document I want to end the process. So far I have tried this:
$(document).click(end_process);
$('div_tag_id').click(start_process);
This is no good as clicking to start the process also ends the process immediately afterwards. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我相信你想要这样的东西:
请参阅:
http://api.jquery.com/event.stopPropagation/
I believe you want something like this:
See:
http://api.jquery.com/event.stopPropagation/
在处理程序中使用
stopPropagation
:Use
stopPropagation
in your handler:当然,您只是想阻止事件在 start_process 处理程序中冒泡:
编辑:看起来每个人都在同一时间说了同样的事情。祝你好运!
Sure, you just want to stop the event from bubbling up in your start_process handler:
Edit: Looks like everyone said about the same thing at the same time. Good luck!
您可以在
start_process
函数中调用.stopPropagation()
来阻止事件冒泡到document
:这是
的文档>.stopPropagation()
: http://api.jquery.com/event.stoppropagation/You can call
.stopPropagation()
in thestart_process
function to stop the event from bubbling up to thedocument
:Here is the documentation for
.stopPropagation()
: http://api.jquery.com/event.stoppropagation/使用
stopPropagation
阻止点击传播到父级。或者,只需将
stopPropagation
添加到start_process
的主体中。Use
stopPropagation
to stop the click from propagating to the parent.alternatively, just add
stopPropagation
into the body ofstart_process
.