开发者

jquery <input type="text" name="quantity[1]" /> get by name

开发者 https://www.devze.com 2023-02-24 11:06 出处:网络
How can I do something like this: Given: <input type=\"text\" name=\"quantity[1]\" /> if ($(\"#开发者_如何学Citem_kit_items\").find(\'input[name=quantity[1]\').length ==1)

How can I do something like this:

Given:

<input type="text" name="quantity[1]" />

if ($("#开发者_如何学Citem_kit_items").find('input[name=quantity[1]').length ==1)
{
    alert('exists');
}

(The above doesn't work)


You must escape the [] characters. Also, you were missing the closing bracket:

$("#item_kit_items").find('input[name=quantity\\[1\\]]')

Alternatively, you can quote the name:

$("#item_kit_items").find('input[name="quantity[1]"]')


You need to quote it and close the brace.

if ($("#item_kit_items").find("input[name='quantity[1]']").length == 1)
0

精彩评论

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