我试图附加一个包含多个标签的字符串,但是每次尝试时都会显示" Uncaught SyntaxError:Unexpected token ILLEGAL"在仅第三个附加,没有该部分,代码工作正常。我做错了什么?
这是我的代码:
$(document).ready(function(){
$("#columnas").on('input',function(){
var cols = $("#columnas").val();
var rows = $("#rows");
rows.empty();
for (i = 1; i <= cols; i++ ) {
rows.append("<input class='linea-campo linea-titulo-ext"+i+"' name='linea-titulo-ext"+i+"' id='linea-titulo-ext"+i+"' type='text' class='form-control' required>");
rows.append("<input class='linea-campo linea-id-ext"+i+"' name='linea-id-ext"+i+"' id='linea-id-ext"+i+"' type='text' class='form-control' required>");
rows.append("<select class='linea-campo linea-sql"+i+"' name='linea-sql"+i+"' id='linea-sql"+i+"'>
<option value='1'>INT</option>
<option value='2'>VARCHAR(MAX)</option>
<option value='3'>DATETIME</option>
<option value='4'>DECIMAL(10,2)</option>
</select>");
rows.append("<input class='linea-campo2 linea-f"+i+"' name='linea-f"+i+"' id='linea-f"+i+"' type='checkbox' class='form-control'>");
rows.append("<input class='linea-campo2 linea-g"+i+"' name='linea-g"+i+"' id='linea-g"+i+"' type='checkbox' class='form-control'>");
rows.append("<input class='linea-campo2 linea-b"+i+"' name='linea-b"+i+"' id='linea-b"+i+"' type='checkbox' class='form-control'>");
}
});
});
答案 0 :(得分:2)
因为它的多行你需要用反斜杠来换行换行符,所以你的第三个附加代码应该是这样的
rows.append("<select class='linea-campo linea-sql"+i+"' name='linea-sql"+i+"' id='linea-sql"+i+"'>\
<option value='1'>INT</option>\
<option value='2'>VARCHAR(MAX)</option>\
<option value='3'>DATETIME</option>\
<option value='4'>DECIMAL(10,2)</option>\
</select>");