.filter(function(index)
2011-12-17 22:15 youxin 阅读(403) 评论(0) 编辑 收藏 举报注意index是从0开始的,A function used as a test for each element in the set. this
is the current DOM element.0-based
<!DOCTYPE html>
<html>
<head>
<style>
div { width:60px; height:60px; margin:5px; float:left;
border:3px white solid; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="first"></div>
<div id="second"></div>
<div id="third"></div>
<div id="fourth"></div>
<div id="fifth"></div>
<div id="sixth"></div>
<script>
$("div").css("background", "#b4b0da")
.filter(function (index) {
return index == 1 || $(this).attr("id") == "fourth";
})
.css("border", "3px double red"); 、、
change the color of all divs; then add a border to the second one (index == 1) and the div with an id of "fourth."
</script>
</body>
</html>