JavaScript: SyntaxError: missing ) 在参数列表之后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15558482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript: SyntaxError: missing ) after argument list
提问by Isma?l tifous
I am getting the error:
我收到错误:
SyntaxError: missing ) after argument list
SyntaxError: 缺少 ) 参数列表后
With this javascript:
使用这个 javascript:
var nav = document.getElementsByClassName('nav-coll');
for (var i = 0; i < button.length; i++) {
nav[i].addEventListener('click',function(){
console.log('haha');
}
}, false);
};
What does this error mean?
这个错误是什么意思?
回答by Ted Hopp
You have an extra closing }
in your function.
您的功能中有一个额外的关闭}
。
var nav = document.getElementsByClassName('nav-coll');
for (var i = 0; i < button.length; i++) {
nav[i].addEventListener('click',function(){
console.log('haha');
} // <== remove this brace
}, false);
};
You really should be using something like JSHintor JSLintto help find these things. These tools integrate with many editors and IDEs, or you can just paste a code fragment into the above web sites and ask for an analysis.
你真的应该使用类似JSHint或JSLint的,以帮助找到这些东西。这些工具与许多编辑器和 IDE 集成,或者您可以将代码片段粘贴到上述网站并要求分析。
回答by Nope
You got an extra }
to many as seen below:
}
如下所示,您获得了更多的额外收益:
var nav = document.getElementsByClassName('nav-coll');
for (var i = 0; i < button.length; i++) {
nav[i].addEventListener('click',function(){
console.log('haha');
} // <-- REMOVE THIS :)
}, false);
};
A very good tool for those things is jsFiddle. I have created a fiddle with your invalid code and when clicking the TidyUp
button it formats your code which makes it clearer if there are any possible mistakes with missing braces.
对于这些事情,一个非常好的工具是jsFiddle。我用您的无效代码创建了一个小提琴,当单击该TidyUp
按钮时,它会格式化您的代码,这使得如果缺少大括号可能存在任何错误,则更加清晰。
DEMO- Your code in a fiddle, have a play :)
演示- 您的代码在小提琴中,玩一玩:)