2

我有一个画廊类型的界面,我正在尝试开始工作,我希望能够在它外部单击以关闭它,但是里面有一个 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/

4

1 回答 1

3

如果您想停止在 上传播 click 事件.theater-container,那么您需要在此处放置命令。现在,您已将其应用于.theater-wrapper单击操作。

$(".theater-container").click(function (ev) {
    ev.stopPropagation();
});
于 2012-01-25T13:29:23.783 回答