jQuery单击关闭元素事件 [英] jQuery click off element event
问题描述
我有一个浮动div,显示,我希望它被隐藏,当用户点击div。当悬停元素时,这将类似于.hover()函数回调。
我试图只为body设置一个click事件,这将隐藏div,但是给出了意想不到的结果。
另一个,可能更简单,选项将是在浮动DIV和页面的其余部分之间添加一个透明div。
透明DIV上的一个简单的点击事件可以处理隐藏,并避免您遇到的点击事件的问题。
I have a floating div that gets displayed, and I want it to be hidden when the user clicks off the div. This would be similar to the .hover() function callback when hovering off an element. Only I want to do this for click.
I tried just setting a click event for the body, which would hide the div, but that gave unexpected results.
Anyone have ideas on how I could easily do this?
Another, possibly simpler, option would be to add a transparent div between the floating DIV and the rest of the page.
A simple click event on the transparent DIV could handle the hiding, and it would avoid the issues you are encountering with the click event.
这篇关于jQuery单击关闭元素事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!