1.查看帶有指定屬性的元素:
[attribute]
例如:
$("div[id]")
2.查看屬性值是某個特定值的元素:
[attribute=value]
例如:
$("input[name='newsletter']").attr("checked", true);
3.匹配所有不含有指定的屬性,或者屬性不等於特定值的元素。
[attribute!=value]
此選擇器等價於:not([attr=value])
要匹配含有特定屬性但不等於特定值的元素,請使用[attr]:not([attr=value])
例如:
$("input[name!='newsletter']").attr("checked", true);
4.匹配給定的屬性是以某些值開始的元素
[attribute^=value]
例如:查找所有 name 以 'news' 開始的 input 元素
$("input[name^='news']")
5.匹配給定的屬性是以某些值結尾的元素
[attribute$=value]
例如:查找所有 name 以 'letter' 結尾的 input 元素
$("input[name$='letter']")
6.匹配給定的屬性是以包含某些值的元素
[attribute*=value]
例如:查找所有 name 包含 'man' 的 input 元素
$("input[name*='man']")
7.復合屬性選擇器,需要同時滿足多個條件時使用。
[selector1][selector2][selectorN]
例如:找到所有含有 id 屬性,並且它的 name 屬性是以 man 結尾的
$("input[id][name$='man']")