【问题标题】:How to ignore multiple classes using the :not selector?如何使用 :not 选择器忽略多个类?
【发布时间】:2012-01-31 17:32:54
【问题描述】:

我在下面有这个选择器,它忽略任何 lishow-all-boxes

$('.boxes li:not([class="show-all-boxes"]) input:checkbox')

添加要被选择器忽略的多个类的最佳方法是什么?我认为可行但行不通的一个例子是:

$('.boxes li:not([class="show-all-boxes, show-all-circles, show-all-triangles"]) input:checkbox')

【问题讨论】:

    标签: jquery jquery-selectors


    【解决方案1】:

    :not 选择器可以将多个 CSS 选择器作为参数 (http://api.jquery.com/not-selector)。例如。

    $('div:not(.a,.b)').empty()
    

    http://jsfiddle.net/HFfcP/

    【讨论】:

    • 没问题塞西尔。顺便说一句,您的第二个代码不起作用,因为它似乎试图匹配所有没有类“show-all-boxes, show-all-circles, show-all-triangles”的lis(逗号和所有)。 jsfiddle.net/56uKS
    【解决方案2】:

    试试这个:

    $('.boxes li').not(".show-all-boxes, .show-all-circles, .show-all-triangles").find('input:checkbox')
    

    【讨论】:

      猜你喜欢
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 2011-10-31
      • 1970-01-01
      • 2021-08-21
      • 2017-06-30
      • 2014-04-14
      相关资源
      最近更新 更多