我怎样才能使这个小提琴工作:http: //jsfiddle.net/gAHwW/
function $escape(string) {
return string.replace(/\\(\[|\]\\)/g,'\\\\$1');
}
$(function() {
$('input[type="button"]').click(function() {
alert($escape( $(this).attr('id') )); // to show you what the escape does
$('#' + $(this).attr('id')).hide(); // doesn't work
$('#' + $escape( $(this).attr('id') )).hide(); // doesn't work
$('#alsosquare[]').hide(); // doesn't work
//$(this).hide(); // works
//$('#alsosquare\\[\\]').hide(); // works
});
});
我需要通过名称/id 动态选择元素,并且它们的名称/id 可以有方括号。
谢谢!