javascript - 未捕获的语法错误 : Unexpected token ILLEGAL in jQuery

标签 javascript jquery

运行 Splunk 示例,我在此函数中遇到错误。

var injectCode = function(code) {
    var sTag = document.createElement("script");
    sTag.type = "text/javascript";
    sTag.text = code;
    $(head).append(sTag);
    return sTag;
}

确切的错误在 $(head).append(sTag); 中。它被放置在 Jade 文件中并在 Node 上运行。我在这里做错了什么?

编辑 - 抱歉,head 定义为 var head = $("head"); 位于函数上方。

并且代码来自这个函数

var getCode = function(id) {
    var code = "";
    $(id + " pre li").each(function(index, line) {
        var lineCode = "";
        $("span" ,line).each(function(index, span) {
            if ($(span).hasClass("com")) {
                lineCode += " ";
            }
            else {
                lineCode += $(span).text();
            }
        });
        lineCode += "\\n";
        code += lineCode;
        });
      return code;
    }

最佳答案

head 是一个标签,使用它:

$('head').append(sTag);

编辑:

我想说删除这个:

lineCode += "\\n";

关于javascript - 未捕获的语法错误 : Unexpected token ILLEGAL in jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17450540/

相关文章:

javascript - 更改输入值或添加新输入(如果不存在)

javascript - jQuery/CSS : selected amount of stars to light up

javascript - polymer 在核心输入上使用功能验证

javascript - PJax - 如何关闭修改后的行为

c# - excanvas js 在 IE8 中不工作

javascript - Backbone.js中不同 View 的调用方法

javascript - 无法将单击事件附加到 JQuery 中的按钮

javascript - jquery 正在删除我的 html 选择

对象中的 JavaScript 函数

javascript - 在此正则表达式中允许 aphrerates