$.has(‘selecor’)和$.filter(‘selector’)方法有什么区别,哪个更好.
因为它们都执行相同的操作.
因为它们都执行相同的操作.
解决方法
它们实际上是完全不同的.
filter
对匹配的元素进行操作:
Reduce the set of matched elements to those that match the selector or pass the function’s test.
has
过滤器基于匹配元素的后代:
Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.
实际例子:
<span class="outer">outer span</span> <div class="outer"> outer div<br> <span>descendant span</span> </div>
$('.outer').filter('span'); //returns the outer span $('.outer').has('span'); //returns the outer div