Syidentifier starts immediately after numeric literal

编程知识 更新时间:2023-05-02 19:01:13

原创地址: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 

更多推荐

Syidentifier starts immediately after numeric literal

本文发布于:2023-04-28 04:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/dc6c5ac786def100ed05ee8d7bea39d8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:starts   Syidentifier   immediately   literal   numeric

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107584文章数
  • 27225阅读数
  • 0评论数