:even and :odd
匹配集合中为偶数或是奇数元素的元素集合。索引以0开始。返回匹配元素集合
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("tr:even").css("background-color", "#bbbbff");
});
</script>
<style>
table {
background:#eeeeee;
}
</style>
</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>
</body>
</html>
$("tr:even").css("background-color", "#bbbbff");
匹配tr元素集合里为偶数tr元素的元素集合。以下为匹配元素集合
<tr><td>Row with Index #0</td></tr>
<tr><td>Row with Index #2</td></tr>