簡體   English   中英

jquery select 元素按名稱屬性

[英]jquery select element by name attribute

我有一個帶有 name 屬性的輸入:

<input type="text" name="data[foo][bar]" />

我怎么能 select 這個元素?

我嘗試$("input[name=data[foo][bar]]")但很有道理。

為屬性值添加引號,否則會出現方括號沖突和解析錯誤:

$("input[name='data[foo][bar]']")
$("input[name='data[foo][bar]']") 
$('input[name="data[foo][bar]"]')

http://api.jquery.com/attribute-equals-selector/了解更多信息

利用

$("input[name=data\\[foo\\]\\[bar\\]]")

文檔說:

如果您希望使用任何元字符(例如,,"#$%&'()*+.:/;?<=>,@[]^`{|}~ )作為 a 的文字部分name:你必須用兩個反斜杠轉義字符。\,例如。如果你有一個id="foo,bar"的元素。你可以使用選擇器$("#foo\.bar")。

http://api.jquery.com/category/selectors/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM