繁体   English   中英

美元符号jQuery作为字符串:未终止的字符串文字

[英]Dollar sign jquery as string : unterminated string literal

我操纵了一些html在模态引导程序中显示一些小形式,如下所示:

$.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'); \
    }; \
  } \
})";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM