码迷,mamicode.com
首页 > Web开发 > 详细

JS错误 Uncaught SyntaxError Unexpected token ILLEGAL

时间:2018-12-20 18:45:09      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:xxx   ken   ...   div   err   erro   变量   事件   ref   

$(‘tbody‘, ‘#‘ + tableId).append(‘<tr onmouseover="this.style.backgroundColor=\‘#eeeeee\‘">xxx</tr>‘);

用js的onmouseover鼠标事件动态改变背景色

如果是this.style.backgroundColor=#eeeeee

将出现Uncaught SyntaxError: Unexpected token ILLEGAL错误 未捕获的SyntaxError:意外的非法标记

 

如果改为this.style.backgroundColor="#eeeeee"或者this.style.backgroundColor=\"#eeeeee\"

将出现Uncaught SyntaxError: Unexpected token }错误  未捕获的SyntaxError:意外的标记 }

因为 onmouseover="this.style.backgroundColor=#eeeeee" 外面已经有一对引号了

正确的做法应该是  onmouseover="this.style.backgroundColor=\‘#eeeeee\‘"  ,总之就是引号标记错误

 

还有更绕的

 

var s = "\""+dataObj[$(th_obj).attr(‘SID‘)]+"\"";
dataObj = "<a href=‘#‘ onMouseOver=‘mouseOver(this,event,"+s+");‘>.....</a>"; //s是变量

在用js,jquery动态添加数据的时候 尤其注意‘  ”有时还需要转义。

 

 

 


 

 

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!希望你也加入到我们人工智能的队伍中来!https://www.cnblogs.com/captainbed

JS错误 Uncaught SyntaxError Unexpected token ILLEGAL

标签:xxx   ken   ...   div   err   erro   变量   事件   ref   

原文地址:https://www.cnblogs.com/skiwnchqhh/p/10150513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!