[英]Passing two parameters to Javascript function
Really really silly question, but I can't get this to work: 确实是一个很愚蠢的问题,但我无法解决这个问题:
http://jsfiddle.net/t4R46/ http://jsfiddle.net/t4R46/
function showOne(parentid, childid){
alert(parentid);
alert(childid);
}
<a href="#" onClick=showOne('div1', 'div2')>91</a>
Basically I want two parameters to be passed to the function but I get: "Uncaught SyntaxError: Unexpected token }" 基本上,我希望将两个参数传递给函数,但我得到:“ Uncaught SyntaxError:Unexpected token}”
Is there any smart site to verify javascripts in? 是否有任何智能网站可在其中验证JavaScript? The error reporting in ie Chrome leaves a bit to be desired.
Chrome中的错误报告还有点不足。
/Patrik /帕特里克
You need quotes around the attribute value: 您需要在属性值两边加上引号:
<a href="#" onClick="showOne('div1', 'div2')">91</a>
<!-- here -----^ and here -----------^ -->
In HTML, an attribute value can only not have quotes if it doesn't have spaces (or a few other characters) in it. 在HTML中,如果属性值中没有空格(或其他一些字符),则不能使用引号。 Since the value you want to set has a space in it, you need to put it in quotes.
由于要设置的值中有空格,因此需要将其放在引号中。
Is there any smart site to verify javascripts in?
是否有任何智能网站可在其中验证JavaScript? The error reporting in ie Chrome leaves a bit to be desired.
Chrome中的错误报告还有点不足。
You're looking for "lint" tools. 您正在寻找“皮棉”工具。 Probably the most famous lint tool for JavaScript is Crockford's
jslint
. 可能最著名的JavaScript皮棉工具是Crockford的
jslint
。 But it is heavily influenced by his personal style and opinions, so there's an active fork called jshint
that's very popular. 但这很大程度上受他的个人风格和见解的影响,因此有一个很受欢迎的叫
jshint
的叉子。 There are online and command-line versions of both. 两者都有在线和命令行版本。 Some IDEs offer lint options as well, such as WebStorm from JetBrains.
某些IDE也提供绒毛选项,例如JetBrains的WebStorm 。
双引号会有所帮助。
<a href="#" onClick="showOne('div1', 'div2')">91</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.