1

私はstackoverflowを検索しましたが、答えが見つかりませんでした。

以下のhtmlをご確認ください

<button type="button" class="nacnchor" value="1">hello</button>
<button type="button" class="nacnchor" value="2">hello</button>
<button type="button" class="nacnchor" value="3">hello</button>

クラスに基づいてボタンのテキストを変更できます

$('button.nacnchor').text("REWRITE");

しかし、属性値に基づいて値を変更したいのですが、$('button.nacnchor,attr(value=1)'):pのようなものはありますか?

4

4 に答える 4

3

属性セレクターは、http: //api.jquery.com/attribute-equals-selector/に記載されています。

$("button.nacnchor[value='1']").text("REWRITE");
于 2013-10-23T12:23:11.790 に答える
1

特定のライブラリの使用方法を探すときは、これ専用のページ全体がある* R *ead * T *he * F *unny * M *anualを使用するのが常に最善です。

...たとえば、は一部のテキストを選択しますが$("a[rel='nofollow']")、選択<a href="example.html" rel="nofollow">Some text</a>しません<a href="example.html" rel="nofollow foe">

セレクター式の属性値は、W3C CSS セレクターの規則に従う必要があります。一般に、これは、有効な識別子以外のものは引用符で囲む必要があることを意味します。

  • 一重引用符内の二重引用符:$('a[rel="nofollow self"]')
  • 二重引用符内の単一引用符:$("a[rel='nofollow self']")
  • 単一引用符内のエスケープされた単一引用符:$('a[rel=\'nofollow self\']')
  • 二重引用符内のエスケープされた二重引用符:$("a[rel=\"nofollow self\"]")
于 2013-10-23T12:25:19.620 に答える
0

以下のコードを試してください

$("button[value='1']").text("REWRITE");
于 2013-10-23T12:25:04.207 に答える