Js 抱错:::SyntaxError: identifier starts immediately after numeric literal

SyntaxError: identifier starts immediately after numeric literal

今天写了个onclick()方法,有这样的一个变量4028b88161c881ff0161c88b80dc0002

需要把这个变量值传入方法内,但始终不成功:

我发现直接将 var aa =4028b88161c881ff0161c88b80dc0002  ;js是抱错的

解决如下:

参考:http://blog.csdn.net/shalousun/article/details/39995443

https://stackoverflow.com/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" ο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://www.cnblogs.com/Amos-Turing/p/8470803.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值