Attribute Equals Selector [name=value]

attributeEquals selector

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

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

描述:选择指定属性是给定值的元素。

Example:

Finds all inputs with name 'newsletter' and changes the text of the span next to it.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <div>

    <input type="radio" name="newsletter" value="Hot Fuzz" />
    <span>name?</span>

  </div>
  <div>
    <input type="radio" name="newsletters" value="Cold Fusion" />

    <span>name?</span>
  </div>
  <div>
    <input type="radio" name="accept" value="Evil Plans" />

    <span>name?</span>
  </div>
<script>$("input[name='newsletter']").next().text(" is newsletter");</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版脚本之家整理、修订 (2011年6月)