gpt4 book ai didi

jquery - 我想从 html 使用 jquery 中排除一些类,例如 $ ('html' ).not ('.classname' ),但它不起作用?

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

我想排除一些使用jquery的类,例如$('html').not('.classname'),但它不起作用?怎么了?

最佳答案

您当前的语法正在尝试选择不具有给定类的 html 标记。

您的 html 标记上可能没有类。

你想要的可能是

$('*:not(.className)')

这将选择除具有给定类的元素之外的所有元素。

或者你可以使用

$("*").not(".className")

这在性能方面是不值得推荐的,因为它会首先选择所有元素,然后才删除那些没有 .className 的元素。

这将选择除给定类的元素之外的所有元素(包括 head、body 等)。

这不是选择元素的有效方法。

如果您的选择更加具体,例如选择所有不带此 className 的 div 元素,效果会更好。

$('div:not(.className)')

或更具体地说,在主 div 内

$('#mainDivId div:not(.className)')

关于jquery - 我想从 html 使用 jquery 中排除一些类,例如 $ ('html' ).not ('.classname' ),但它不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40902067/

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