【发布时间】:2012-01-14 07:09:57
【问题描述】:
考虑一个输入元素
<input id="meta[152][value]" type="text" />
这里的输入字段是动态生成的。我需要选择该字段。所以我用了,
alert($('#meta[152][value]').val());
但这似乎是无效的。搜索后发现,“方括号”需要像#meta\\[152\\]\\[value\\]一样转义
那么该怎么做呢? 我目前使用这个代码,
var id = "#meta[152][value]" // (I get this value by another method) I need the escaping to be done here. So that i can use as
/** 我需要使用正则表达式、替换或任何其他方法来转义 id 的值 得到#meta\[152\]\[value\] 而不是手动**/
alert($(id).val());
您的建议会有所帮助!
【问题讨论】:
标签: javascript jquery regex jquery-selectors escaping