<html>
<head>
<meta charset="utf-8" />
</head><script type="text/javascript">function fun(key) {
alert(key);
}</script><body onload=test(["hi", "hi2"])></body>
</html>
<head>
<meta charset="utf-8" />
</head><script type="text/javascript">function fun(key) {
alert(key);
}</script><body onload=test(["hi", "hi2"])></body>
</html>
<head>
<meta charset="utf-8" />
</head><script type="text/javascript">function test(key) {
alert(key);
}</script><body onload=test(["hi", "hi2"])></body>
</html>
修改完代码,还是不能执行啊
我想要做的是在onclick里调用JS函数,并且在这里向该函数传 JS对象,为何就不行呢?
["hi", "hi2"]不就是JS对象么:(
<head>
<meta charset="utf-8" />
</head><script type="text/javascript">function test(key) {
alert(key);
}</script><body onload=test(["hi", "hi2"])></body>
</html>
修改完代码,还是不能执行啊
我想要做的是在onclick里调用JS函数,并且在这里向该函数传 JS对象,为何就不行呢?
["hi", "hi2"]不就是JS对象么:(
在标准里面是这么写的:
In certain cases, authors may specify the value of an attribute without any quotation s. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation s even when it is possible to eliminate them.
属性不加引号的情况是属性值只包含字母、数字、连字符、点号、下划线和冒号。
所以onload=test(["hi", "hi2"])应该加上引号,为onload='test(["hi", "hi2"])'
<head>
<meta charset="utf-8" />
</head><script type="text/javascript">function test(key) {
alert(key);
}</script><body onload=test(["hi", "hi2"])></body>
</html>
修改完代码,还是不能执行啊
我想要做的是在onclick里调用JS函数,并且在这里向该函数传 JS对象,为何就不行呢?
["hi", "hi2"]不就是JS对象么:(
加单引号
<body onload='test(["hi", "hi2"])'>