将js事件绑定到除1个元素之外的文档 [英] Bind js event to document except 1 element

查看:137
本文介绍了将js事件绑定到除1个元素之外的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个弹出窗口,想要在外面的任何地方点击它时隐藏它,但是一个元素(这是另一个弹出窗口,比如div#AnotherPopup)。然后我点击#AnotherPopup,它不应该隐藏原来的..它现在,因为我有这个:

Basically I have a popup and want to hide it when it is clicked anywhere outside, but one element (which is another popup, let say div#AnotherPopup). Then I click on #AnotherPopup, it should not hide the original one.. It does now, because I have this:

  $(document).bind('click', methods.hide);

如何将它绑定到文档,除了#AnotherPopup? :)

How to bind it to document, except #AnotherPopup ? :)

推荐答案

你不能真的,但你可以在里面检查 methods.hide 如果目标元素是 #AnotherPopup 并且在做任何事情之前立即退出函数。

You can't really but you can check inside methods.hide if the target element is #AnotherPopup and immediately return out of the function before doing anything.

这篇关于将js事件绑定到除1个元素之外的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆