总有人间一两风,填我十万八千梦

jQuery .:even Selector 用法 手册 | 示例代码

jQuery开发手册 归档 185℃ 0评论

描述: 选择所引值为偶数的元素,从 0 开始计数。 也可以查看 odd.

  • 添加的版本: 1.0jQuery( “:even” )

特别地注意的是,这是基于0的索引,所以:even选择器是选择第一个元素,第三个元素,依此类推在匹配。

Additional Notes:(其他注意事项:)

  • 因为:even 是一个 jQuery 延伸出来的选择器,并不是的CSS规范的一部分,使用:even 查询不能充分利用原生DOM提供的querySelectorAll() 方法来提高性能。为了当使用:even 的时候在现代浏览器上获得更佳的性能,首先使用纯CSS选择器选择元素,然后使用.filter(":even").
  • 查找表格中索引值是偶数的行(即实际表格中的奇数行),即匹配第一行、第三行、第五行等 (索引值是 0, 2 ,4 等 )。

例子:

Finds even table rows, matching the first, third and so on (index 0, 2, 4 etc.).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html>
<head>
<style>
table {
background:#eeeeee;
}
</style>
<script src="https://code.jquery.com/jquery-latest.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>

转载请注明:悠然品鉴 » jQuery .:even Selector 用法 手册 | 示例代码

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址