jquery过滤选择器
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../jquery.js"></script>
</head>
<body>
<div id="father">
<div>
1
<div></div>
<div></div>
<div></div>
</div>
<div>
2
<li></li>
<li></li>
</div>
<div>
3
</div>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</div>
<script>
$(function(){
/*
:eq(index) 获取到元素中,选择索引号为2的元素,索引号index从0开始
:odd 获取到元素中,选择索引号为奇数的元素
:even 获取到元素中,选择索引号为偶数的元素
*/
console.log($('#father>div:eq(1)').height(100).width(100).css('backgroundColor','red'));
$('#father>li:odd').css('color','red')
$('#father>li:even').css('color','blue')
})
</script>
</body>
</html>
标签:jquery,color,元素,father,索引,过滤,odd,选择器,css 来源: https://blog.csdn.net/deep_zhuheihei/article/details/123066083