[attribute*=value] 返回值:Array<Element(s)>
概述
匹配给定的属性是以包含某些值的元素
参数
attributeString
属性名
value (可选)String
属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。
示例
描述:
查找所有 name 包含 'man' 的 input 元素
HTML 代码:
<input name="man-news" />
<input name="milkman" />
<input name="letterman2" />
<input name="newmilk" />
jQuery 代码:
$("input[name*='man']")
结果:
[ <input name...
[attribute$=value] 返回值:Array<Element(s)>
概述
匹配给定的属性是以某些值结尾的元素
参数
attributeString
属性名
value (可选)String
属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。
示例
描述:
查找所有 name 以 'letter' 结尾的 input 元素
HTML 代码:
<input name="newsletter" />
<input name="milkman" />
<input name="jobletter" />
jQuery 代码:
$("input[name$='letter']")
结果:
[ <input name="newsletter" />, &l...
[attribute^=value] 返回值:Array<Element(s)>
概述
匹配给定的属性是以某些值开始的元素
参数
attributeString
属性名
value (可选)String
属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。
示例
描述:
查找所有 name 以 'news' 开始的 input 元素
HTML 代码:
<input name="newsletter" />
<input name="milkman" />
<input name="newsboy" />
jQuery 代码:
$("input[name^='news']")
结果:
[ <input name="newsletter" />, <inpu...
[attribute!=value] 返回值:Array<Element(s)>
概述
匹配所有不含有指定的属性,或者属性不等于特定值的元素。
此选择器等价于:not([attr=value])
要匹配含有特定属性但不等于特定值的元素,请使用[attr]:not([attr=value])
参数
attributeString
属性名
value (可选)String
属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。
示例
描述:
查找所有 name 属性不是 newsletter 的 input 元素
HTML 代码:
<input type="checkbox" name="newsletter" value="Hot Fuzz" />
<input type=&qu...
[attribute=value] 返回值:Array<Element(s)>
概述
匹配给定的属性是某个特定值的元素
参数
attributeString
属性名
value (可选)String
属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。
示例
描述:
查找所有 name 属性是 newsletter 的 input 元素
HTML 代码:
<input type="checkbox" name="newsletter" value="Hot Fuzz" />
<input type="checkbox" name="newsletter" value="Cold Fusion" />
<input type="checkbox" na...
[attribute] 返回值:Array<Element(s)>
概述
匹配包含给定属性的元素。注意,在jQuery 1.3中,前导的@符号已经被废除!如果想要兼容最新版本,只需要简单去掉@符号即可。
参数
attributeString
属性名
示例
描述:
查找所有含有 id 属性的 div 元素
HTML 代码:
<div>
<p>Hello!</p>
</div>
<div id="test2"></div>
jQuery 代码:
$("div[id]")
结果:
[ <div id="test2"></div> ]
...
hasAttribute [simulated]
hasAttribute(element, attribute) -> Boolean
为不存在该方法的浏览器(Internet Explorer 6 或 7)模拟规范中指定的 DOM 方法 hasAttribute。
样例
<a id="link" href="http://prototypejs.org">Prototype</a>
$('link').hasAttribute('href');
// -> true
...
writeAttribute [1.6]
writeAttribute(element, attribute[, value = true]) -> HTMLElement
writeAttribute(element, attributes) -> HTMLElement
新增、修改或移除指定的 element 属性。属性参数可以是一个 hash 对象,也可以是一个名/值对。
readAttribute
readAttribute(element, attribute) -> String | null
返回 elemnet 由参数 attribute 指定的属性值,若不存在指定的属性值,返回 null。
提供这个方法主要是基于以下两个目的:首先,它对 getAttribute 做了简单的封装,在 Safari 和 Internet Explorer 下,getAttribute 并不是一个“真正”的函数对象(它没有 .apply 或 .call 实例方法)。 其次,它清理了 Internet Explorer 处理属性时造成的可怕的混乱。
样例
<a id="tag" href="/tags/prototype" rel="tag" title="view related bookmarks." my_widget="some info.">Prototyp...
writeAttribute(element, attribute[, value = true]) -> HTMLElement
writeAttribute(element, attributes) -> HTMLElement
新增、修改或移除指定的 element 属性。属性参数可以是一个 hash 对象,也可以是一个名/值对。
readAttribute(element, attribute) -> String | null
返回 elemnet 由参数 attribute 指定的属性值,若不存在指定的属性值,返回 null。
提供这个方法主要是基于以下两个目的:首先,它对 getAttribute 做了简单的封装,在 Safari 和 Internet Explorer 下,getAttribute 并不是一个“真正”的函数对象(它没有 .apply 或 .call 实例方法)。 其次,它清理了 Internet Explorer 处理属性时造成的可怕的混乱。
样例
<a id="tag" href="/tags/prototype" rel="tag" title="view related bookmarks." my_widget="some info.">Prototype</a>
$('tag...