转载:http://blog.csdn.net/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>

错误:SyntaxError: identifier starts immediately after numeric literal的更多相关文章

  1. E QUERY [main] SyntaxError: identifier starts immediately after numeric literal mongodb mapReduce 异常分析 集合命名规范

    异常信息 repl_test:PRIMARY> db.0917order_totals_b.find()2018-09-28T15:13:03.992+0800 E QUERY [main] S ...

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

    SyntaxError: identifier starts immediately after numeric literal 今天写了个onclick()方法,有这样的一个变量4028b88161 ...

  3. SyntaxError:identifier starts immediately after numeric literal

    1.错误描写叙述 2.错误原因 因为在改动方法传參的过程,须要传个id,可是这个id是字符串类型,传入的是数值型 3.解决的方法 在传參时,须要加入"",变成字符串类型 User. ...

  4. 使用onclick报SyntaxError: identifier starts immediately after numeric literal

    少了‘’ 错误 onclick="onlineWatch(${row.title})" 正确 onclick="onlineWatch('${row.title}')&q ...

  5. js 传参报错 参数含有数字、字母组合的字符串SyntaxError: identifier starts immediately after numeric literal

    报错的意思是标识符以数字开头,这是因为js是弱类型的语言当发现第一个数字是就自动转化为数字类型的但是其中还含有字符所以报了错,‘ 报错的原因是因为我们想传的字符串,但是js却当成数字,所以需要给传的参 ...

  6. javascript中出现identifier starts immediately after numeric literal错误原因以及解决方法

    javascript遇到参数是字符型和数字型组合的参数就会出现这种错误,例如alert(1);可以正確輸出alert(str);就會報錯alert("str");可以正確輸出.

  7. jQuery 事件函数传参异常identifier starts immediately after numeric literal

    问题情境: var arr=[aabbcc,112233]; var html = ""; for(var i =0;i<arr.length;i++){ html += ' ...

  8. js错误 SyntaxError: missing : after property id

    在用jquery的post方法时 $.post('adminCheckTpmisPlans.do',{'test',str},function(f){ ... }) 报如下错误 SyntaxError ...

  9. 【微信】微信小程序 微信开发工具中新创建的json文件,编译报错VM1781:2 pages/module/module.json 文件解析错误 SyntaxError: Unexpected end of JSON input

    如果新创建报错:编译报错VM1781:2 pages/module/module.json 文件解析错误  SyntaxError: Unexpected end of JSON input 解决方法 ...

随机推荐

  1. python3笔记二十三:正则表达式之元字符

    一:学习内容 匹配单个字符与数字:..[].^.\d.\D.\w.\W.\s.\S 匹配锚字符(边界字符):^.$.\A.\Z.\b.\B 匹配多个字符:(xyz) .x?.x*..*.x+.x{n} ...

  2. Error in render: "TypeError: Cannot read property 'url_img' of undefined"

    如果我们 vue 组件中 template 里面添加了下标(靠数组索引得到的值),就会报索引为 undefined 解决方法: 在我们使用下标时,要在父组件上做条件判断,如果这个下标存在,然后就显示里 ...

  3. cygwin执行.py提示找不到模块,但已经安装模块的解决办法

    . 在解决了cygwin中make命令不能使用的问题之后(https://www.cnblogs.com/zhenggege/p/10724122.html),make maskrcnn路径下的set ...

  4. LC 646. Maximum Length of Pair Chain

    You are given n pairs of numbers. In every pair, the first number is always smaller than the second ...

  5. vue echarts圆角阴影效果

    series: [ { name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20], itemStyle: { normal: { barBorder ...

  6. 【React自制全家桶】八、React动画以及react-transition-group动画库的使用

    React动画通常有三种方法实现从易到难为: 1.transition(CSS3自带) 2.animation(CSS3自带) 3.react-transition-group动画库(需要引入插件) ...

  7. liunx服务器在本地可以访问但是外网访问不了

    版权声明:本文为CSDN博主「tlytg456」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明.原文链接:https://blog.csdn.net/tlytg/ar ...

  8. linux 基础 复制window文件到linux

    1.下载pscp工具:地址 2.dos执行命令: pscp F:\his.rar root@192.168.3.137:/tmp/test

  9. 使用第三方UITableView+FDTemplateLayoutCell计算cell行高注意点

    现在很方便的计算单元格的行高大部分都是使用的第三方框架UITableView+FDTemplateLayoutCell,不知道你在使用这个框架的时候有没有遇到和我一样的问题,比如: 在这样计算cell ...

  10. ubuntu install themes && use it

    one step: I am going to show you the installation of a theme with Numix theme and Unity Tweak Tool. ...