运行 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/