jQuery('[attribute~="value"]')
attribute
An attribute name.
attribute:属性名称
value
An attribute value. Can be either an unquoted single word or a quoted string.
value:属性值。引号是可选的。
Description: Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.
This selector matches the test string against each word in the attribute value, where a "word" is defined as a string delimited by whitespace. The selector matches if the test string is exactly equal to any of the words.
描述:选择所有指定属性用空格分隔后的属性值中包含给定的字符串的元素。
Example:
Finds all inputs with a name attribute that contains the word 'man' and sets the value with some text.
例子:查找所有name属性值中包含'man'的input元素,然后将值改为其他文字。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input name="man-news" />
<input name="milk man" /> <!--this works-->
<input name="letterman2" />
<input name="newmilk" />
<script>$('input[name~="man"]').val('mr. man is in it!');</script>
</body>
</html>
attribute
An attribute name.
attribute:属性名称
value
An attribute value. Can be either an unquoted single word or a quoted string.
value:属性值。引号是可选的。
Description: Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.
This selector matches the test string against each word in the attribute value, where a "word" is defined as a string delimited by whitespace. The selector matches if the test string is exactly equal to any of the words.
描述:选择所有指定属性用空格分隔后的属性值中包含给定的字符串的元素。
Example:
Finds all inputs with a name attribute that contains the word 'man' and sets the value with some text.
例子:查找所有name属性值中包含'man'的input元素,然后将值改为其他文字。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input name="man-news" />
<input name="milk man" /> <!--this works-->
<input name="letterman2" />
<input name="newmilk" />
<script>$('input[name~="man"]').val('mr. man is in it!');</script>
</body>
</html>