返回值:jQueryfilter(fn)
概述
篩選出與指定函數(shù)返回值匹配的元素集合
這個函數(shù)內部將對每個對象計算一次 (正如 '$.each'). 如果調用的函數(shù)返回false則這個元素被刪除,否則就會保留。
參數(shù)
fnFunction
傳遞進filter的函數(shù)
示例
描述:
保留子元素中不含有ol的元素。
HTML 代碼:
<p><ol><li>Hello</li></ol></p><p>How are you?</p>
jQuery 代碼:
$("p").filter(function(index) {
return $("ol", this).length == 0;
});
結果:
[ <p>How are you?</p> ]