gpt4 book ai didi

jQuery $ ('html, body' ).not()

转载 作者:行者123 更新时间:2023-12-03 22:53:55 25 4
gpt4 key购买 nike

here - 我希望当您单击任意位置但不在 div 上时发出警报。

当我点击 div 时,也会显示警报。

JS

$("html, body").not('.entry-content').click(function() {            
alert('d');
}); ​

HTML

<div class="entry-content"> kkkk </div>​

最佳答案

您可以使用事件参数来查看单击了哪个目标并返回 false

$("html, body").click(function(e) {
if ($(e.target).hasClass('entry-content')) {
return false;
}
alert('d');
});​

http://jsfiddle.net/keyZw/

您正在使用 .not() 过滤器..但它仍然是 html/body 的一部分..因此您需要在 click 函数内处理它。另外你只是绑定(bind)点击事件..

所以

 // find html,body - not ones with class=entry-content - bind click
$("html, body").not('.entry-content')

因此这不会阻止警报,因为您的 div 仍在体内

如前所述..你只需要真正绑定(bind)到主体

$("body").click(function(e) {
if ($(e.target).hasClass('entry-content')) {
return false;
}
alert('d');
});​

关于jQuery $ ('html, body' ).not(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12958734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com