jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
filter(filter) |
filter(filter) 从匹配的元素集合中删除那些不符合指定的筛选条件的元素(即返回与指定表达式匹配的元素集合)。这个方法用于缩小搜索的范围。 返回值:jQuery 参数:
删除所有拥有一个ol子元素的元素。 $("p").filter(function(index) { return $("ol", this).length == 0; }) HTML 代码: <p><ol><li>Hello</li></ol></p><p>How are you?</p> 结果: [ <p>How are you?</p> ] filter( filter ) Removes all elements from the set of matched elements that do not pass the specified filter. This method is used to narrow down the results of a search. Return value: jQuery
Example: Remove all elements that have a child ol element $("p").filter(function(index) { return $("ol", this).length == 0; })Before: <p><ol><li>Hello</li></ol></p><p>How are you?</p>Result: [ <p>How are you?</p> ] |