JQ 点击元素以外位置关闭元素
评论 2 热度 1509
方法一:
给document绑定click事件,判断点击的时候是否点到了el
元素,判断没点到就关闭。
$(document).bind("click", function (e) {
if($(e.target).closest("el").length <= 0){
$("el").hide();
}
});
方法二:
同样给document绑定click事件,如果点到元素内部,则阻止事件函数执行。
$(document).click(function(){
$("el").hide();
});
$("el").click(function(event){
event.stopPropagation();
});
亿泽 Windows 10 · FireFox
混眼熟啦!
#100 2018-08-31 08:18 回复
Luuljh Windows 7 · Google Chrome
dalao nihao
#102 2018-08-31 09:08 回复