当前位置: 移动技术网 > IT编程>开发语言>Jquery > jQuery :even

jQuery :even

2018年01月25日  | 移动技术网IT编程  | 我要评论

此选择器匹配所有索引值为偶数的元素,从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教程参阅板块。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网