1

次のような入力ボックスがいくつかあります。

<input type="checkbox" name="checkbox_item[500]" />
<input type="checkbox" name="checkbox_item[10]" />
<input type="checkbox" name="checkbox_item[2]" />
<input type="checkbox" name="checkbox_item[1]" />
<input type="checkbox" name="checkbox_item[]" />

checkbox_item\[\d+\]したがって、正規表現テスターでうまく機能する次の正規表現パターンを使用していますが、Jquery では機能しません。これは私のJqueryコードです:

console.log($("input:regex(name, /checkbox_item\[\d+\]/)").length);

私は4を期待していましたが、代わりに28になりました!

誰かがこれに光を当てることができますか?

ありがとう

4

3 に答える 3

1

I don’t think jQuery natively supports regular expressions in selectors in that way.

But you could use the Attribute Starts With Selector [name^="value"].

于 2013-10-02T10:37:16.670 に答える
1

属性の開始を like で使用できます

console.log($("input[type=checkbox][name^='checkbox_item']").length)

デモ

于 2013-10-02T10:38:04.783 に答える