jquery 关闭点击?
当我通过 jquery 的“点击”点击“链接”时,我有一个“li”弹出。
有谁知道一种干净的方法可以按照“offclick”的方式做一些事情?比如,当我单击元素时,它会隐藏弹出窗口吗?
谢谢! 马特
I have a 'li' that pops down when I click on a 'link' via jquery's 'click'.
Does anyone know of a clean way to do something along the lines of 'offclick'? As in, when I click off of the element, it would hide the pop down?
Thanks!
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能希望为窗口分配一个点击侦听器,并将点击侦听器分配给您的链接。在链接单击侦听器内,您需要停止事件传播,以便它不会沿 DOM 树向上传播并触发窗口的单击侦听器。
像这样的事情应该可以解决问题:
You would want to assign a click listener to the window and also assign the click listener to your link. Inside the link click listener, you'll want to stop the event propagation so it doesn't travel up the DOM tree and fire your window's click listener.
Something like this should do the trick:
我想你可以看看模糊,当元素失去焦点时调用它:
参考: http://api.jquery.com/blur/
I guess you could look at blur, which is called when the element looses focus:
ref: http://api.jquery.com/blur/
您可以使用
blur
或focusout
根据您的需要You can use
blur
orfocusout
depending on your needs