jQuery通过单击主体关闭/切换div [英] jQuery close/toggle div by clicking body
本文介绍了jQuery通过单击主体关闭/切换div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个小jsFiddle中,我正在尝试 http://jsfiddle.net/PcWjA/22/进行ul显示:单击主体(或列表项中的 not 的任何地方)时无,并且第一次单击主体时无济于事.但是之后,该脚本似乎循环并显示/隐藏ul以闪烁.
In this small jsFiddle http://jsfiddle.net/PcWjA/22/ I am trying to make a ul go display:none when there's a click on the body (or anywhere not on the list items) and that workst the first time there's a click on the body. But after that the script seems to loop and shows/hides the ul to flash.
推荐答案
我还有另一个答案 http://jsfiddle.net/FfBzT/
jQuery(document).ready(function() {
jQuery('.hour_dropdown').hide()
$(window).click(function (event) {
if ($(event.target).hasClass("hour_dropdown") ||
$(event.target).parents(".hour_dropdown").size() > 0 ||
$(event.target).hasClass("more")){
// do nothing....
} else {
$('.hour_dropdown').fadeOut(200);
}
});
jQuery('.more').click(function() {
//if ($('.hour_dropdown').css("display")=="none") {
$('.hour_dropdown').fadeToggle(200);
//}
});
});
这篇关于jQuery通过单击主体关闭/切换div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文