admin管理员组文章数量:1130349
SyntaxError: identifier starts immediately after numeric literal
今天写了个onclick()方法,有这样的一个变量4028b88161c881ff0161c88b80dc0002
需要把这个变量值传入方法内,但始终不成功:
我发现直接将 var aa =4028b88161c881ff0161c88b80dc0002 ;js是抱错的
解决如下:
参考:http://blog.csdn/shalousun/article/details/39995443
https://stackoverflow/questions/14966133/syntaxerror-identifier-starts-immediately-after-numeric-literal-in-firebug
$(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/Amos-Turing/p/8470803.html
SyntaxError: identifier starts immediately after numeric literal
今天写了个onclick()方法,有这样的一个变量4028b88161c881ff0161c88b80dc0002
需要把这个变量值传入方法内,但始终不成功:
我发现直接将 var aa =4028b88161c881ff0161c88b80dc0002 ;js是抱错的
解决如下:
参考:http://blog.csdn/shalousun/article/details/39995443
https://stackoverflow/questions/14966133/syntaxerror-identifier-starts-immediately-after-numeric-literal-in-firebug
$(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/Amos-Turing/p/8470803.html
本文标签: SyntaxErroridentifierJS抱错numeric
版权声明:本文标题:Js 抱错:::SyntaxError: identifier starts immediately after numeric literal 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754577127a2703704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论