gpt4 book ai didi

jquery - 单击正文,但其他一些标签不起作用

转载 作者:行者123 更新时间:2023-12-01 02:46:40 26 4
gpt4 key购买 nike

有谁知道 css position:relative;可能会搞乱函数

    $('body').not($('.theDIV')).click(function(){
alert('');

});

或者问题出在其他地方?

发生的情况是,我有一个在单击按钮时出现的图标,并且当我单击主体上除 div 本身之外的任何位置时,我希望它隐藏()。 HTML

<ul class='messages'> //these are made dynamically. should i use each() to go through all the elements?
<li>
<div class='theDIV'></div>
<input type='button'>
</li>
<li>
<div class='theDIV'></div>
<input type='button'>
</li>
<li>
<div class='theDIV'></div>
<input type='button'>
</li>
</ul>

抱歉,如果我第一次不清楚

最佳答案

你可以做

$('body').click(function(e){
if(! $(e.target).hasClass('theDIV')){
alert('clicked on something that has not the class theDIV');
}

});

关于jquery - 单击正文,但其他一些标签不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9711134/

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