admin 管理员组文章数量: 1184232
在用javascript时,当你使用一个字符传作为函数的参数常常会看到语法错误,在firebug下会报SyntaxError: identifier starts immediately after numeric literal ,当然在google下提示就不准确了。
或者报509edbe9-2914-431f-9128-97d368b7da0b undefined
错误原因是:标识符以数字开头
下面直接看例子吧:
$(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>
本文标签: starts identifier SyntaxError literal numeric
版权声明:本文标题:SyntaxError: identifier starts immediately after numeric literal 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1738235794a1948210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论