首頁  >  選擇器  > [attribute!=value]

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

概述

匹配所有不含有指定的屬性,或者屬性不等於特定值的元素。

此選擇器等價于 :not([attr=value]) 要匹配含有特定屬性但不等於特定值的元素,請使用[attr]:not([attr=value])

參數

attribute String V1.0

屬性名

value String V1.0

屬性值。引號在大多數情況下是可選的。但在遇到諸如屬性值包含"]"時,用以避免衝突。

示例

描述:

查詢所有 name 屬性不是 newsletter 的 input 元素

HTML 程式碼:

<input type="checkbox" name="newsletter" value="Hot Fuzz" />
<input type="checkbox" name="newsletter" value="Cold Fusion" />
<input type="checkbox" name="accept" value="Evil Plans" />
jQuery 程式碼:

$("input[name!='newsletter']").attr("checked", true);
結果:

[ <input type="checkbox" name="accept" value="Evil Plans" checked="true" /> ]