:even Selector
even selector
version added: 1.0jQuery(':even')
描述: 选择偶数元素,从 0 开始计数。同样查看奇数的
特别地注意的是,这是基于0的索引,所以:even
选择器是选择第一个元素,第三个元素,依此类推在匹配。
Example:
Finds even table rows, matching the first, third and so on (index 0, 2, 4 etc.).
<!DOCTYPE html>
<html>
<head>
<style>
table {
background:#eeeeee;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<table border="1">
<tr><td>Row with Index #0</td></tr>
<tr><td>Row with Index #1</td></tr>
<tr><td>Row with Index #2</td></tr>
<tr><td>Row with Index #3</td></tr>
</table>
<script>$("tr:even").css("background-color", "#bbbbff");</script>
</body>
</html>