運行Splunk示例並在此函數中出現錯誤。未捕獲SyntaxError:jQuery中的意外令牌ILLEGAL
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文件中,它在節點上運行。我在這裏做錯了什麼?
編輯 - 對不起,head
被定義爲右var head = $("head");
功能的上方。
而且code
來源於此功能
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'存在嗎?也許它應該是'document.head'? –
你從哪裏得到錯誤? – SLaks