我得到了一些非常奇怪的语法错误,没有捕获到SyntaxError:看似正常的代码的意外标识符。
如果我在else块的第1行之后写入任何内容,则会出现错误。
if (classlist.length == 0) {
lastClickCatID = -1;
}
else {
lastClickCatID = +classlist.value.split('-')[1];
// **Getting error if I write anything here, even for comments like this**
}如果我只在注释中使用两个单词(它们之间有一个空格),就会得到错误。当然,任何JS语句都会出错,即使是基本的控制台日志也是如此。
另外,在下面的代码中得到一个console.log行的错误,它已经被注释掉了(第四行: console.log-"UNDO"):
// Push this data into the undo array
undo.push([lastClickDivID, lastClickCol, lastClickRow, lastClickCatID, nextClickCatID]);
//console.log("UNDO", undo[0][0], undo[0][1], undo[0][2], undo[0][3], undo[0][4]); // *Getting error if I include this line*
console.log(undo.pop());使用或不使用注释标记都会出现错误。但是如果我删除整行代码,它就能正常工作。
我还有另外一句话:
nextClickCatID = +id2;在执行变量的console.log操作时,再次得到错误。但如果我去掉'+‘,只使用下一个'nextClickCatID = id2;’就可以了。
在这个函数中还得到了许多类似的奇怪错误(如果我包含它们,它会变得太长)。你知道为什么看起来很正常的代码会出现这样的错误吗?
发布于 2017-08-16 19:22:10
我已经解决了。当我删除jquery文档就绪函数中()和花括号之间的空格时,它的工作方式很奇怪。从...
$(function() {至:
$(function(){ // with no space between the parentheses and the curly brackets我想补充一点--它之前在相同的结构(括号之间有空格)下一直工作得很好。但今天突然决定在特定函数中给出一个错误。如果有人能澄清为什么会发生这种情况,它仍然是非常相关的。
https://stackoverflow.com/questions/45708729
复制相似问题