jQuery 事件函数传参异常identifier starts immediately after numeric literal
问题情境:
var arr=[aabbcc,112233];
var html = "";
for(var i =0;i<arr.length;i++){
html += '<li id="'+arr[i]+'" onclick="select('+arr[i]+')">helloworld</li>'
}
$("ul").append(html);
function select(id){
var identifier = "#" + id;
$(identifier).html(); //抛异常的位置
}
分析:
jQuery的ID选择器要用的是字符串,当传给ID选择器的是数字时会抛异常。将参赛改为字符串即可。
更正:
循环体中的onclick="select('+arr[i]+')"改为onclick="select(\''+arr[i]+'\')"。\是转义符,用单引号将参数包裹起来。
jQuery 事件函数传参异常identifier starts immediately after numeric literal的更多相关文章
- 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 ...
- Js 抱错:::SyntaxError: identifier starts immediately after numeric literal
SyntaxError: identifier starts immediately after numeric literal 今天写了个onclick()方法,有这样的一个变量4028b88161 ...
- 错误:SyntaxError: identifier starts immediately after numeric literal
转载:http://blog.csdn.net/shalousun/article/details/39995443在用JavaScript时,当你使用一个字符传作为函数的参数常常会看到语法错误,在f ...
- js 传参报错 参数含有数字、字母组合的字符串SyntaxError: identifier starts immediately after numeric literal
报错的意思是标识符以数字开头,这是因为js是弱类型的语言当发现第一个数字是就自动转化为数字类型的但是其中还含有字符所以报了错,‘ 报错的原因是因为我们想传的字符串,但是js却当成数字,所以需要给传的参 ...
- SyntaxError:identifier starts immediately after numeric literal
1.错误描写叙述 2.错误原因 因为在改动方法传參的过程,须要传个id,可是这个id是字符串类型,传入的是数值型 3.解决的方法 在传參时,须要加入"",变成字符串类型 User. ...
- javascript中出现identifier starts immediately after numeric literal错误原因以及解决方法
javascript遇到参数是字符型和数字型组合的参数就会出现这种错误,例如alert(1);可以正確輸出alert(str);就會報錯alert("str");可以正確輸出.
- 使用onclick报SyntaxError: identifier starts immediately after numeric literal
少了‘’ 错误 onclick="onlineWatch(${row.title})" 正确 onclick="onlineWatch('${row.title}')&q ...
- jquery插件函数传参错误
1.jquery传参通过json,可能的错误是,参数中的结束符写成了;
- pytest_函数传参和firture传参数request
前言为了提高代码的复用性,我们在写用例的时候,会用到函数,然后不同的用例去调用这个函数. 比如登录操作,大部分的用例都会先登录,那就需要把登录单独抽出来写个函数,其它用例全部的调用这个登陆函数就行. ...
随机推荐
- Condition使用
面试题:写一个固定容量同步容器,拥有put和get方法,以及getCount方法, 能够支持2个生产者线程以及10个消费者线程的阻塞调用 有两种方法 1.使用wait和notify/notify ...
- redis 命令clear、set、get、del、rename、keys *、exists、type、expire、expireat、persist、ttl、move、select
清屏 clear 新增/修改set 查询get 删除del 修改key rename old new 查询所有的key keys *查询一个key是否存在 exists,有返回1,没有返回0查询值的类 ...
- shrio的简单认识
博客讲解; shrio的知识储备 shrio的简单认识 笔记整理地址: Shrio.pdf 下载 Shrio理论.doc 下载 shrio知识储备.doc 下载
- Week5——applet
1.定义 applet是一种Java程序.它一般运行在支持Java的Web浏览器内.因为它有完整的Java API支持,所以applet是一个全功能的Java应用程序. 2.特点(不同于Java a ...
- Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; then appstreamcli refresh > /dev/null; fi'
运行sudo apt-get update 时Ubuntu 16.04出现: Problem executing scripts APT::Update::Post-Invoke-Success 'i ...
- shell_script2
一.函数 1.简介 Shell函数类似于Shell脚本,里面存放了一系列的指令 不过,Shell的函数存在于内存,而不是硬盘文件,所以速度很快 另外,Shell还能对函数进行预处理,所以函数的启动比脚 ...
- 将虚拟网络连接到 ExpressRoute 线路
本文通过使用 Resource Manager 部署模型和 Azure 门户,帮助将虚拟网络 (VNets) 链接到 Azure ExpressRoute 线路. 虚拟网络可以在同一个订阅中,也可以属 ...
- systemd 之 systemctl
Systemd 常规操作与彩蛋 一.前言 上了俩个月的RHCE工程师的班,收获颇多.话说回来,在 redhat 7 中有个非常重要的概念,即:systemd systemd 是 Linux 下的一款系 ...
- 使用django的admin的后台管理界面
django的admin后台管理界面是方便我们对数据库操作的 是一个在浏览器显示的 图形化界面数据库操作 我们先在django中的admin中把我们需要在图形化界面中进行操作的表导入进去: 先把m ...
- Error:Could not find com.android.tools.build:gradle:3.0.0
Error:Could not find com.android.tools.build:gradle:3.0.Searched in the following locations: file ...