首頁  >  選擇器  > [attribute]

返回值:Array<Element(s)>[attribute]

jQuery [attribute] 選擇器概述

匹配包含給定屬性的元素。注意,在jQuery 1.3中,前導(dǎo)的@符號(hào)已經(jīng)被廢除!如果想要兼容最新版本,只需要簡(jiǎn)單去掉@符號(hào)即可。

參數(shù)

attributeStringV1.0

屬性名

示例

描述:

查找所有含有 id 屬性的 div 元素

HTML 代碼:
<div>
  <p>Hello!</p>
</div>
<div id="test2"></div>
jQuery 代碼:
$("div[id]")
結(jié)果:
[ <div id="test2"></div> ]