jQuery 元素选择器和属性选择器允许您通过标签名, 属性名或内容对 html 元素进行选择. 下面我们就来看一下 jQuery 有哪些属性选择器?
jQuery 属性选择器是基于元素属性作为筛选条件的选择器.
[attribute] 属性名选择器
[attribute=value] 属性值选择器
[attribute!=value] 非属性值选择器
[attribute^=value] 属性值以某个字符串开头的选择器
[attribute$=value] 属性值以某个字符串结尾的选择器
[attribute*=value] 属性值中包含某个字符串的选择器
[selector1][selector2][selectorN] 多属性选择器 (交集属性选择器)
详细介绍:
[attribute] 属性名选择器
选择拥有该属性名的元素.
- var a=$('[id]');
- console.log(a);
[attribute=value] 属性值选择器
选择属性值为某个特定值的元素.
- var a=$('[id=one]');
- console.log(a);
[attribute!=value] 非属性值选择器
选择所有属性值不为特定值的元素 (包括没有该属性的元素)
- var a=$('[class!=eukaryotes_animal]');
- console.log(a);
[attribute^=value] 属性值以某个字符串开头的选择器
- var a=$('[class^=eukaryotes]');
- console.log(a);
[attribute$=value] 属性值以某个字符串结尾的选择器
- var a=$('[class$=plant]');
- console.log(a);
[attribute*=value] 属性值中包含某个字符串的选择器
- var a=$('[class*=yotes_m]');
- console.log(a);
[selector1][selector2][selectorN] 多属性选择器 (属性交集选择器)
- var a=$('[class^=eukaryotes_][id]');
- console.log(a);
本文来自 jQuery 答疑 https://www.html.cn/qa/jquery/ 栏目, 欢迎学习!
来源: http://www.css88.com/qa/jquery/16850.html