错误:SyntaxError: identifier starts immediately after numeric literal

编程知识 更新时间:2023-05-02 18:56:48
转载:http://blog.csdn/shalousun/article/details/39995443
在用JavaScript时,当你使用一个字符传作为函数的参数常常会看到语法错误,在firebug下会报SyntaxError: identifier starts immediately after numeric literal ,当然在google下提示就不准确了。 错误原因是:标识符以数字开头 下面直接看例子吧: $(function(){
var str = "509edbe9-2914-431f-9128-97d368b7da0b"; //错误的写法 var html = '<button class="button" id="ensure" οnclick="test(str)">确定</button>';//把字符串作为参数传给函数,直接报错 //正确的写法 var html = '<button class="button" id="ensure" οnclick="test(\''+str+'\')">确定</button>';//正确执行,注意第一个\后是两个单引号 $("#dd").append(html); }); function test(id){ console.log(id); } <div id="dd"></div>

 

转载于:https://wwwblogs/llljpf/p/6676489.html

更多推荐

错误:SyntaxError: identifier starts immediately after numeric literal

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

发布评论

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

>www.elefans.com

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

  • 107534文章数
  • 27218阅读数
  • 0评论数