不是 jQuery 中的类选择器
是否有一个简单的选择器表达式来不选择具有特定类的元素?
<div class="first-foo" />
<div class="first-moo" />
<div class="first-koo" />
<div class="first-bar second-foo" />
我只想获取前三个 div 并尝试
$(div[class^="first-"][class!="first-bar"])
,但这会收到所有内容,因为最后一个 div 包含的内容多于第一个栏。有没有办法在这样的表达式中使用占位符?类似的东西
$(div[class^="first-"][class!="first-bar*"]) // doesn't seem to work
还有其他可能有帮助的选择器吗?
Is there a simple selector expression to not select elements with a specific class?
<div class="first-foo" />
<div class="first-moo" />
<div class="first-koo" />
<div class="first-bar second-foo" />
I just want to get the first three divs and tried
$(div[class^="first-"][class!="first-bar"])
But this receives all as the last div contains more than first-bar. Is there a way to use a placeholder in such an expression? Something like that
$(div[class^="first-"][class!="first-bar*"]) // doesn't seem to work
Any other selectors that may help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要
:not()
选择器:或者,
.not()
方法:You need the
:not()
selector:or, alternatively, the
.not()
method:您可以使用
:not
过滤选择器:或
not()
方法:更多信息:
You can use the
:not
filter selector:Or
not()
method:More Info:
您可以在“not”方法中编写 jQuery 选择器:
$('div[class^="first-"]').not($('.first-bar'))
You can write a jQuery selector in the "not" method:
$('div[class^="first-"]').not($('.first-bar'))
它还适用于带有
:not()
选择器的 jQuery 事件。就像这样:
在我的例子中,我启用对
< 的每个
的点击/code> 期望所有具有
deleted
类 ()
It also works on jQuery events with
:not()
selector.Simply like this :
In my case, I enable click on every
<td class="clickable">
of<tr class="fo-line">
expected all withdeleted
class (<tr class="fo-line deleted">
)