Attribute Contains Word Selector [name~=value]
attributeContainsWord selector
version added: 1.0jQuery('[attribute~=value]')
- attribute
- 一個屬性名.
- value
- 一個屬性值,引號是可選的.
描述:選擇指定屬性用空格分隔的值中包含一個給定值的元素。
這個選擇器測試屬性值中的每個單詞字符串,其中“word”是一個由空白分隔的字符串定義的。如果測試字符串恰好等于任何一個字詞這個選擇器將選擇。
Example:
Finds all inputs with a name attribute that contains the word 'man' and sets the value with some text.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<input name="man-news" />
<input name="milk man" />
<input name="letterman2" />
<input name="newmilk" />
<script>$("input[name~=man]").val("mr. man is in it!");</script>
</body>
</html>