admin管理员组文章数量:1130349
原创地址:http://my.oschina/xinyuan6009/blog/164418
js异常:javascript Firebug error: Identifier starts immediately after numeric literal
异常原因:标识符以数字开头异常分析:
示例1· ?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<
html
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=iso-8859-1"
>
<
title
>Untitled Document</
title
>
<
script
>
function test(id,content){
alert(id);
}
</
script
>
</
head
>
<
body
>
<
button
onclick
=
"test(1,this);"
>测试</
button
>
</
body
>
</
html
>
|
示例2·
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<
html
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=iso-8859-1"
>
<
title
>Untitled Document</
title
>
<
script
>
function test(id,content){
alert(id);
}
</
script
>
</
head
>
<
body
>
<
button
onclick
=
"test(1aaa,this);"
>测试</
button
>
</
body
>
</
html
>
|
从上面可以看出:js脚本中,函数参数可以是以下几种情况:
1·字符串
2·数字
3·定义好的js对象
示例2中参数之一是1aaa,这样的参数本首先当作一个对象识别,但是js标识符并不能以数字开头。所以报错
解决办法:在参数传入之前将其转换为字符串,形式如下test('1aaa',this);
但是这种情况下,如果test函数是由js脚本动态生成,也就是说test函数本身就是由字符串拼成的会出现一种情况,就是拼接后生成的代码出现错位。。。很诡异,不知道原因。解决办法是将字符串中的函数用\"test('"+1aaa+"')\"包起来。
参考文章:
http://stackoverflow/questions/14966133/syntaxerror-identifier-starts-immediately-after-numeric-literal-in-firebug
http://stackoverflow/questions/17358351/syntaxerror-identifier-starts-immediately-after-numeric-literal
http://stackoverflow/questions/5883397/javascript-firebug-error-identifier-starts-immediately-after-numeric-literal
原创地址:http://my.oschina/xinyuan6009/blog/164418
js异常:javascript Firebug error: Identifier starts immediately after numeric literal
异常原因:标识符以数字开头异常分析:
示例1· ?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<
html
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=iso-8859-1"
>
<
title
>Untitled Document</
title
>
<
script
>
function test(id,content){
alert(id);
}
</
script
>
</
head
>
<
body
>
<
button
onclick
=
"test(1,this);"
>测试</
button
>
</
body
>
</
html
>
|
示例2·
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<
html
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=iso-8859-1"
>
<
title
>Untitled Document</
title
>
<
script
>
function test(id,content){
alert(id);
}
</
script
>
</
head
>
<
body
>
<
button
onclick
=
"test(1aaa,this);"
>测试</
button
>
</
body
>
</
html
>
|
从上面可以看出:js脚本中,函数参数可以是以下几种情况:
1·字符串
2·数字
3·定义好的js对象
示例2中参数之一是1aaa,这样的参数本首先当作一个对象识别,但是js标识符并不能以数字开头。所以报错
解决办法:在参数传入之前将其转换为字符串,形式如下test('1aaa',this);
但是这种情况下,如果test函数是由js脚本动态生成,也就是说test函数本身就是由字符串拼成的会出现一种情况,就是拼接后生成的代码出现错位。。。很诡异,不知道原因。解决办法是将字符串中的函数用\"test('"+1aaa+"')\"包起来。
参考文章:
http://stackoverflow/questions/14966133/syntaxerror-identifier-starts-immediately-after-numeric-literal-in-firebug
http://stackoverflow/questions/17358351/syntaxerror-identifier-starts-immediately-after-numeric-literal
http://stackoverflow/questions/5883397/javascript-firebug-error-identifier-starts-immediately-after-numeric-literal
本文标签: startsSyidentifierImmediatelyliteralnumeric
版权声明:本文标题:Syidentifier starts immediately after numeric literal 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754578035a2703792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论