juqery 学习之三 选择器 可见性 元素属性

2020-05-18 08:46:42易采站长站整理


Matches elements that have the specified attribute and it starts with a certain value.
返回值

Array<Element>


参数

attribute (String) : 属性名


value ( String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含”]”时,用以避免冲突。


示例

查找所有 name 以 ‘news’ 开始的 input 元素


HTML 代码:


<input name=”newsletter” />
<input name=”milkman” />
<input name=”newsboy” />

jQuery 代码:


$(“input[name^=’news’]”)

结果:


[ <input name=”newsletter” />, <input name=”newsboy” /> ]

—————————————————————————————


[attribute$=value]匹配给定的属性是以某些值结尾的元素

Matches elements that have the specified attribute and it ends with a certain value.
返回值

Array<Element>


参数

attribute (String) : 属性名


value (String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含”]”时,用以避免冲突。


示例

查找所有 name 以 ‘letter’ 结尾的 input 元素


HTML 代码:


<input name=”newsletter” />
<input name=”milkman” />
<input name=”jobletter” />

jQuery 代码:


$(“input[name$=’letter’]”)

结果:


[ <input name=”newsletter” />, <input name=”jobletter” /> ]

—————————————————————————————


[attribute*=value]匹配给定的属性是以包含某些值的元素

Matches elements that have the specified attribute and it contains a certain value.
返回值

Array<Element>


参数

attribute (String) : 属性名


value (String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含”]”时,用以避免冲突。


示例

查找所有 name 包含 ‘man’ 的 input 元素