jQuery单击事件为document但忽略一个div [英] jQuery click event for document but ignore a div
问题描述
我遇到的问题是我的工作让我在页面底部插入一个注释框,当有人点击评论框或保存注释按钮时,它也会触发页面的点击事件。
有没有办法可以为整个页面点击事件,但是当有人点击DIV中的评论框/保存按钮时,忽略它?
您很可能需要使用事件对象的 stopPropagation()
方法:
($)$ {code $ $''''''''''''
如果不能尝试使用 preventDefault()
:
e.preventDefault();
I have a online Slide Show I'm working on using jQuery. I have use $(document).click event to detect when a user clicks on the page to know when to show the next bullet point in the slide or to move to the next page.
The problem I'm running into is my job had me insert a comment box on the bottom of the page and when ever someone clicks on the comment box or the save comment button it also fires the click event for the page.
Is there a way I can have the click event for the entire page but ignore it when someone clicks in the DIV the Comment box/Save button are in?
You will most likely need to stop the propagation of events in your Comments div using the event object's stopPropagation()
method:
$('#comments').click(function(e) {
e.stopPropagation();
});
if that doesn't work try using preventDefault()
:
e.preventDefault();
这篇关于jQuery单击事件为document但忽略一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!