jQuery 点击事件停止传播无法工作?
我有一个画廊类型的界面,我试图开始工作,我希望能够单击它的外部来关闭它,但是里面有一个 div,其中包含主要元素、照片和要单击的内容。然而,就像现在一样,当您在 div 内部单击时,它会关闭,因为它是元素中的子元素,当您单击时,它会关闭。
我有这样的 div:
<div class="theater-wrapper">
<div class="theater-container"></div>
</div>
所有内容都通过 ajax 加载到剧院容器中。 当您单击 .theater-wrapper 时,它应该触发事件关闭,但是当您单击 Theater-container 时,它不应该触发该事件。
这就是我尝试关闭它的方式:
$(".theater-wrapper").click(function (event) {
$('.theater-wrapper').hide();
event.stopPropagation();
});
我有一个 jsfiddle 显示此操作: http://jsfiddle.net /Cs8Kq/1/
I have a gallery type of interface that I'm trying to get to work, I want to be able to click outside of it to close it, however there is a div inside that contains the main elements, photos, and things to click. However as it is now when you click inside the div it closes, because it's a child in the element that when you click it closes.
I have the divs like this:
<div class="theater-wrapper">
<div class="theater-container"></div>
</div>
everything is loaded into theater-container via ajax.
When you click .theater-wrapper it should fire the event to close, however when you click theater-container it shouldn't.
This is how I have tried to close it:
$(".theater-wrapper").click(function (event) {
$('.theater-wrapper').hide();
event.stopPropagation();
});
I have a jsfiddle showing this in action: http://jsfiddle.net/Cs8Kq/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想停止在
.theater-container
上传播点击事件,那么您需要在其中放置命令。现在您已将其应用于.theater-wrapper
点击操作。If you want to stop propagation of the click event on
.theater-container
, then that's where you need to put the command. Right now you have it applied to the.theater-wrapper
click action.