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

 

posted on 2016-03-23 23:01  wts_crazy  阅读(398)  评论(0编辑  收藏  举报