读书人

jquery的find的filter的差异[转载]

发布时间: 2012-11-07 09:56:10 作者: rapoo

jquery的find的filter的区别[转载]
filter will select a certain subset (zero or more) of the already
selected elements.
jquery的filter将在一组已经选取的元素里面选择
find will select a set of (zero or more) elements that are descendants
of the already selected elements.
jquery的find将在一组已经选取的元素的子节点里面选择

Here is an example:
示例如下

1. <div class="peanuts">
2. <p class="elephants"></p>
3. </div>
4. <div class="elephants">
5. <p></p>
6. </div>

$(‘div’).filter(‘.elephants’); // < selects the second div, because
it has class=”elephants”

$(‘div’).find(‘.elephants’); // < selects the first paragraph,
because it has class=”elephants”

* Note that these two examples are very simple and would probably be
better written as …

$(‘div.elephants’);

… and …

$(‘div .elephants’);

Popularity: 39%

http://www.juyimeng.com/difference-between-jquery-find-and-filter.html

读书人网 >Web前端

热点推荐