jQuery 如何使用 :not 选择器忽略多个类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8699366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to ignore multiple classes using the :not selector?
提问by Cecil Theodore
I have this selector below where it ignores any li
with the class show-all-boxes
我在下面有这个选择器,它忽略li
类中的任何内容show-all-boxes
$('.boxes li:not([class="show-all-boxes"]) input:checkbox')
What is the best way of adding multiple classes to be ignored by the selector? An example of this that I thought would work but it doesn't is:
添加选择器忽略的多个类的最佳方法是什么?我认为会起作用但不起作用的一个例子是:
$('.boxes li:not([class="show-all-boxes, show-all-circles, show-all-triangles"]) input:checkbox')
回答by Thong Kuah
The :not selector can take multiple CSS selectors as arguments ( http://api.jquery.com/not-selector). E.g.
:not 选择器可以将多个 CSS 选择器作为参数(http://api.jquery.com/not-selector)。例如
$('div:not(.a,.b)').empty()
回答by redmoon7777
try this :
尝试这个 :
$('.boxes li').not(".show-all-boxes, .show-all-circles, .show-all-triangles").find('input:checkbox')