Javascript jQuery append()方法显示未超出的非法令牌错误?
我正试图通过Javascript jQuery append()方法显示未超出的非法令牌错误?,javascript,jquery,json,Javascript,Jquery,Json,我正试图通过jquery.append()方法在html中插入materialize.css代码,但它一直显示“意外的非法令牌”错误。 我感到困惑,并认为这可能是由于转义序列字符或反斜杠 $(“.container”).append(“ “+”问题“+页面id+” “+第页,问题+” “+页面。选项[0]+” “+第页。选项[1]+” “+第页。选项[2]+” “+第页选项[3]+” 请选择一个选项 提交 "); $(“.container”).append(` 问题${page.id
jquery.append()
方法在html中插入materialize.css代码,但它一直显示“意外的非法令牌”错误。
我感到困惑,并认为这可能是由于转义序列字符或反斜杠
$(“.container”).append(“
“+”问题“+页面id+”
“+第页,问题+”
“+页面。选项[0]+”
“+第页。选项[1]+”
“+第页。选项[2]+”
“+第页选项[3]+”
请选择一个选项
提交
");代码>
$(“.container”).append(`
问题${page.id}
“+第页,问题+”
${page.option[0]}
${page.option[1]}
${page.option[2]}
${page.option[3]}
请选择一个选项
提交
`);代码>
您不能使用append()
函数追加内容。这样,您应该包含以下行:
$(".container").append("<div class='row'>"+
"<div class='col s12 m12'>"+
"<div class='card teal accent-1 hoverable' id='car'>"+
"<div class='card-content center-align'>"+
"<span class='card-title'>" + "Question" + page.id +"</span>"+
"<form action='#'>"+
"<p>"+page.question+"</p>"+
"<p><input name='group1' type='radio' id='test1' />"+
"<label for='test1'>"+page.option[0]+"</label></p>"+
"<p><input name='group1' type='radio' id='test2' />"+
"<label for='test2'>"+page.option[1]+"</label></p>"+
"<p><input name='group1' type='radio' id='test3' />"+
"<label for='test3'>"+page.option[2]+"</label></p>"+
"<p><input name='group1' type='radio' id='test4' />"+
"<label for='test4'>"+page.option[3]+"</label></p>"+
"</form>"+
"<h6 id='error1'>Please select an option</h6>"+
"</div>"+
"<div class='card-action center'>"+
"<button class='btn' id='submit1'>Submit</button>"+
"</div>"+
"</div>"+
"</div>"+
"</div>");
$(“.container”).append(“'+
""+
""+
""+
“+”问题“+页面id+”+
""+
“”+第页。问题+“”+
“”+
“+页面。选项[0]+””+
“”+
“+页面。选项[1]+””+
“”+
“+页面。选项[2]+””+
“”+
“+第页。选项[3]+””+
""+
“请选择一个选项”+
""+
""+
“提交”+
""+
""+
""+
"");
希望这有帮助
意外的非法令牌?
您需要使用+
对html的每一行进行压缩,并需要在双引号中引用它
$(".container").append("<div class='row'>"+
"<div class='col s12 m12'>"+
.......
"</div>"+
"</div>");
$(“.container”).append(“'+
""+
.......
""+
"");
给你一个解决方案
$(“.container”).append(`
问题${page.id}
“+第页,问题+”
${page.option[0]}
${page.option[1]}
${page.option[2]}
${page.option[3]}
请选择一个选项
提交
`);代码>
这对我来说非常有效。谢谢。我意识到在一行中连接多行的错误。