我操纵了一些 html 以在模态 Bootstrap 中显示一个小表单,如下所示:
$.each(response, function(i, item){
detail += "<div><input name='detail-tipe' type='checkbox' value='" + response[i].nama_detail + "' class='detail-tipe' /> " + response[i].nama_detail.toString() + "</div>";
});
detail += "$('.detail-tipe').each(function(){
var attrib = $(this).attr('value');
for ( var j=0, k = remo.length; j < k; j++ ) {
if(attrib == remo[j]){
$(this).attr('checked', 'checked');
};
}
})";
但是,美元符号未终止。是否可以 敬请指教。
最佳答案
如果要将多行字符串赋给变量,则需要在每行末尾放置一个\
,告诉解释器该字符串是连续的。否则它认为您想要开始新的实际代码行。
detail += "$('.detail-tipe').each(function(){ \
var attrib = $(this).attr('value'); \
for ( var j=0, k = remo.length; j < k; j++ ) { \
if(attrib == remo[j]){ \
$(this).attr('checked', 'checked'); \
}; \
} \
})";
关于javascript - 美元符号 jquery 作为字符串 : unterminated string literal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41460282/