find和filter的区别

1、find和filter的用法

find表示从子集中选择符合条件的对象;

filter表示从自身过滤出符合条件的对象;

2、源代码

<script type="text/javascript">
$(function(){ 								    //  等待DOM加载完毕.
	//lzz:实验find和filter方法,前者是在内部查找符合条件的,后者是过滤自身符合条件的
	$("#a1").find("#b1").css("background","red");
	$("#a1 div").filter(":eq(1)").css("background","blue");
})
</script>
<div id="a1" style="width:50px;height:50px;clear:both;background:#FC3">
    <div id="b1" style="width:10px;height:20px;">b1</div>
    <div id="b2" style="width:10px;height:20px;">b2</div>
    <div id="b3" style="width:10px;height:20px;">b3</div>
</div>

3、效果图


猜你喜欢

转载自blog.csdn.net/lzzmandy/article/details/79986663
今日推荐