jquery中has方法

如果传入选择器,has()会返回一个新的jquery对象,

仅包含有子孙元素匹配该选择器的选中元素。如果传,

入文档元素给has(),它会将选中元素集调整为那些

是指定元素祖先节点的选中元素。

例如:

<p>
    <a href="baidu.com">1</a>
</p>
<p>
    <a href="baidu.com">1</a>
</p>
<p>
    <a href="baidu.com">1</a>
    <a href="baidu.com">1</a>
    <a href="baidu.com">1</a>
    <a href="baidu.com">1</a>
</p>
<p>
    <a>1</a>
</p>

console.debug($("p").has("a[href]").size());//3

原文地址:https://www.cnblogs.com/sdwrz/p/5313572.html