admin管理员组文章数量:1130349
转载: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" onclick="test(str)">确定</button>';//把字符串作为参数传给函数,直接报错 //正确的写法 var html = '<button class="button" id="ensure" onclick="test(\''+str+'\')">确定</button>';//正确执行,注意第一个\后是两个单引号 $("#dd").append(html); }); function test(id){ console.log(id); } <div id="dd"></div>
转载于:https://wwwblogs/llljpf/p/6676489.html
转载: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" onclick="test(str)">确定</button>';//把字符串作为参数传给函数,直接报错 //正确的写法 var html = '<button class="button" id="ensure" onclick="test(\''+str+'\')">确定</button>';//正确执行,注意第一个\后是两个单引号 $("#dd").append(html); }); function test(id){ console.log(id); } <div id="dd"></div>
转载于:https://wwwblogs/llljpf/p/6676489.html
本文标签: 错误identifierSyntaxErrorstartsnumeric
版权声明:本文标题:错误:SyntaxError: identifier starts immediately after numeric literal 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754577284a2703721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论