gpt4 book ai didi

jquery 单击选择元素(如果它不在特定类中)

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

我正在尝试这样做,但到目前为止没有人知道如何在单击时选择元素但不包括特定 div 中的元素,如 .box以及 div .box 中的所有内容

小更新:感谢您的回复,但如果我使用 :nothasClass它不能确保 foo 内的元素不会被选中。喜欢:

<div class=foo>this won't be selected <span>this will</span></div>

最佳答案

您可以使用hasClass()方法:

$('a').click(function() {
if (!(this).hasClass('foo')) {
// the clicked element doesn't have the foo class
}
return false;
});

关于jquery 单击选择元素(如果它不在特定类中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4298359/

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