: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:

jQuery 1.6 API 中文版脚本之家整理、修订 (2011年6月)