开发者

jquery select element by name attribute

开发者 https://www.devze.com 2023-03-11 16:35 出处:网络
I have an input with the name attribute: 开发者_开发问答<input type=\"text\" name=\"data[foo][bar]\" />

I have an input with the name attribute:

开发者_开发问答<input type="text" name="data[foo][bar]" />

how can I select this element?

I tried $("input[name=data[foo][bar]]") but in vein.


Add quotes to the attribute value, otherwise you get conflicting square brackets and a parse error:

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


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


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

http://api.jquery.com/attribute-equals-selector/ for more info


Use

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

The documentation says:

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \. For example, if you have an element with id="foo.bar", you can use the selector $("#foo\.bar").

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

0

精彩评论

暂无评论...
验证码 换一张
取 消