;(function($){
$.fn.clickOtherHide = function () {
var $this = this;//注意this在这后是否被解绑,如果解绑了,插件就失效了。
$this.off("click").on("click",function(e){
stopPropagation(e);//相当于return false;即阻止冒泡,不冒泡到父元素的点击事件。
});
$(document).off("click").on("click",function(e){
//这里是判断弹框里的二级弹框,如果是点击的二级弹框,则不隐藏。
var tat = $(e.target);
var k = tat.parents("XXX").length;
if(k && k > 0){
stopPropagation(e);
}else{
$this.css('display','none');
}
});
function stopPropagation(e) {
if (e.stopPropagation)
e.stopPropagation();
else
e.cancelBubble = true;
}
};
})(jQuery);
点击控件以外的地方隐藏控件
最新推荐文章于 2021-10-12 17:28:30 发布