我有一个叠加层,我想在它外面的 mousedown
上隐藏它。
这是我尝试过的,但不幸的是 :not
选择器没有像我预期的那样工作。
$('body:not(.overlay)').one('mousedown',function(){
//hide overlay here
});
我也试过 $('* :not(.overlay)')
但同样的问题。
即使在叠加框内单击,叠加层也会隐藏
最佳答案
$(document).on( "mousedown.hideoverlay", function(e){
if( $(e.target).closest(".overlay").length === 0 ) { //overlay wasn't clicked.
//hide overlay
$(document).off("mousedown.hideoverlay");
}
});
关于javascript - 使用 :not to select all elements except inside box with certain class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11289425/