:not() Selector
not selector
version added: 1.0jQuery(':not(selector)')
- selector
- 一個(gè)用來過濾的選擇器。
Description: 選擇所有去除不匹配給定的選擇器的元素。
所有的選擇器可以放置在 :not()中,例如 :not(div a) 和 :not(div,a)。
Additional Notes
.not()方法通常更快,最終可能會(huì)提供一個(gè)更可讀的選擇,你選擇或較復(fù)雜的變量在: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>