此选择器匹配所有索引值为偶数的元素,从0开始计数。
jQuery1.0版本添加。
语法结构:
jQuery( ":even" )
代码实例:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂蚁部落</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#bt").click(function () { $("li:even").css("color", "blue"); }); }); </script> </head> <body> <ul> <li>蚂蚁部落一</li> <li>蚂蚁部落二</li> <li>蚂蚁部落三</li> <li>蚂蚁部落四</li> </ul> <input type="button" value="查看效果" id="bt" /> </body> </html>
将索引值为偶数的li元素的字体颜色设置为蓝色。
原文地址是jQuery :even一章节。
jQuery教程参阅jQuery教程板块。