Attribute Contains Selector [name*=value]

attributeContains selector

version added: 1.0jQuery('[attribute*=value]')

  • attribute
    一个属性名.
    value
    一个属性值,引号是可选的.

描述: 选择指定属性具有包含一个给定的子字符串的元素。(选择给定的属性是以包含某些值的元素)

这是最慷慨的jQuery的属性选择器匹配一个值。如果选择器的字符串内的任何地方出现的元素的属性值,它会被选择。比较这个词的选择选择属性包含(例如:[attr~=word]),更重要的是在许多情况下适当的。

Example:

Finds all inputs with a name attribute that contains '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="milkman" />
  <input name="letterman2" />
  <input name="newmilk" />
<script>$("input[name*='man']").val("has man in it!");</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版Clove整理、修订