:not() Selector

not selector

version added: 1.0jQuery(':not(selector)')

  • selector
    一个用来过滤的选择器。

Description: 选择所有去除不匹配给定的选择器的元素。

所有的选择器可以放置在 :not()中,例如 :not(div a):not(div,a)

Additional Notes

.not()方法通常更快,最终可能会提供一个更可读的选择,你选择或较复杂的变量在:not()选择滤波器中。

Example:

Finds all inputs that are not checked and highlights the next sibling span. Notice there is no change when clicking the checkboxes since no click events have been linked.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <div>
  <input type="checkbox" name="a" />
  <span>Mary</span>
</div>

<div>
  <input type="checkbox" name="b" />
  <span>lcm</span>

</div>
<div>
  <input type="checkbox" name="c" checked="checked" />

  <span>Peter</span>
</div>
<script>
  $("input:not(:checked) + span").css("background-color", "yellow");
  $("input").attr("disabled", "disabled");

</script>

</body>
</html>

Demo:

设计酷,jquery1.6 api中文手册