单击实时选择器外部
如果用户单击页面上该元素之外的任何位置,我想使用 live 方法隐藏该元素。它与 clickoutside 插件 的功能完全相同,但使用的是 ajax 加载的元素。关于如何做到这一点有什么想法吗?
I want to use the live method to hide an element if the user clicks anywhere on the page outside of that element. It is exactly like what clickoutside plugin does, but with ajax loaded elements. Any ideas on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样的东西
Something like
您可以执行以下操作:
工作原理:如果您单击该元素,则单击事件不会冒泡,从而导致单击
元素。如果您在元素外部单击,它会冒泡,最终到达隐藏您的元素的
。
You can do this:
How it works: If you click on the element, the click event doesn't bubble up, causing a click on the
<body>
element. If you click outside the element though, it bubbles up, eventually getting to<body>
which hides your element.有一个适用于实时的 clickoutside 事件的修改版本的示例: http://benalman.com/news/2010/03/jquery-special-events/#highlighter_680190
There is an example a modified version of the clickoutside event that works with live: http://benalman.com/news/2010/03/jquery-special-events/#highlighter_680190