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:

设计酷,jquery1.6 api中文手册