filter()和find()方法都非常相似,除了前者适用于所有元素,而后者仅搜索子元素。
要简单
- filter()–搜索所有元素。
- find()–仅搜索所有子元素。
jQuery filter()vs find()示例
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63<html> <head> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <style type="text/css"> div{ padding:8px; border:1px solid; } </style> </head> <body> <h1>jQuery find() vs filter() example</h1> <script type="text/javascript"> $(document).ready(function(){ $("#filterClick").click(function () { $('div').css('background','white'); $('div').filter('#Fruits').css('background','red'); }); $("#findClick").click(function () { $('div').css('background','white'); $('div').find('#Fruits').css('background','red'); }); }); </script> </head><body> <div id="Fruits"> Fruits <div id="Apple">Apple</div> <div id="Banana">Banana</div> </div> <div id="Category"> Category <div id="Fruits">Fruits</div> <div id="Animals">Animals</div> </div> <br/> <br/> <br/> <input type='button' value='filter(Fruits)' id='filterClick'> <input type='button' value='find(Fruits)' id='findClick'> </body> </html>
试试演示
标签: jQuery的 jQuery的穿越
翻译自: https://mkyong.com/jquery/difference-between-filter-and-find-in-jquery/
最后
以上就是花痴白猫最近收集整理的关于jQuery中filter()和find()之间的区别的全部内容,更多相关jQuery中filter()和find()之间内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复