【问题标题】:jQuery: unexpected token ILLEGAL [duplicate]jQuery:意外令牌非法 [重复]
【发布时间】:2013-04-29 10:13:37
【问题描述】:

找不到我的问题的解决方案,所以我会在这里问。

当我插入 jQuery 文件时,我在第 2 行得到一个错误: 意外令牌非法

代码:

jQuery(document).ready(function(){
    $('body').append('
        <div id="style_selector">
        <div id="style_selector_container">
        // another chunk of code
        </div><!-- #style_selector end -->');
});

提前谢谢你

【问题讨论】:

  • JavaScript 不支持这样的多行字符串。要么放在一行上,要么用\ 转义结尾。

标签: javascript jquery html append


【解决方案1】:
jQuery(document).ready(function(){
    $('body').append('<div id="style_selector"><div id="style_selector_container"></div>');
});

这将完成这项工作。因为当您使用 jquery 附加内容时,它不能包含新行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 2015-10-19
    • 2011-05-23
    • 1970-01-01
    相关资源
    最近更新 更多