【发布时间】:2011-11-22 17:52:14
【问题描述】:
为什么选择器在第一个示例中有效,但在第二个示例中失败? 见jsfiddle。
<div id="hello[1][2]_world"> </div>
<textarea id="console"></textarea>
<script>
$(document).ready(function() {
//first example
$('#hello\\[1\\]\\[2\\]_world').html('01234'); //everything is OK
//second example
var iid = 'hello[1][2]_world';
iid = iid.replace(/[#;&,.+*~':"!^$[\]()=>|\/]/g, "\\\\$&");
$('#console').val(iid); //see in textarea, the same string as from first
$('#'+iid).html('56789'); //not working! whyyyyyyyy? :)
});
</script>
【问题讨论】:
标签: javascript jquery