在 jQuery 中,如果你想使用 :not()
选择器来排除表格行 (tr
) 中的多个条件,有几种方法可以实现。
$('tr').not('.class1').not('.class2')
或者:
$('tr:not(.class1):not(.class2)')
$('tr:not(.class1, .class2)')
假设你有一个表格,想选择所有不包含 "hidden" 类且不是第一个子元素的行:
$('tr:not(.hidden, :first-child)')
或者排除具有特定属性和类的行:
$('tr:not([data-ignore], .disabled)')
选择器之间是"或"的关系,不是"与"的关系
选择器性能:复杂的选择器可能影响性能,特别是在大型表格中
可以结合其他选择器使用,如 $('table#myTable tr:not(.hidden, .deleted)')