This question already has answers here:
How do I break a string across more than one line of code in JavaScript?
                            
                                (10个答案)
                            
                    
                6年前关闭。
        

    

这是我的问题的jsFiddle demo

触发click事件后,此jquery代码段会添加3个div。但是,控制台显示“未捕获的语法错误:意外的令牌
脚本

$('#e16').on('click', function(){
 $(this).append("<div id='e17' class='kim2bb'>Alcohol 0.2+</div>
                 <div id='e18' class='kim2bb'>Alcohol 1.0~2.0</div>
                 <div id='e19' class='kim2bb'>Alcohol 0.05~1.0</div>");
});


html

<div id="e16" class="kim2bb">Drunken Drive</div>

最佳答案

您有一个字符串分成多行:

$(this).append("<div id='e17' class='kim2bb'>Alcohol 0.2+</div>" +
                "<div id='e18' class='kim2bb'>Alcohol 1.0~2.0</div>" +
                "<div id='e19' class='kim2bb'>Alcohol 0.05~1.0</div>");

10-05 20:47