分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

JS错误 Uncaught SyntaxError ?Unexpected token ILLEGAL

发布时间:2023-09-06 02:27责任编辑:胡小海关键词:暂无标签
$(‘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

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved