JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL
2014-01-12 11:05
459 查看
$('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动态添加数据的时候 尤其注意‘ ”有时还需要转义。
相关文章推荐
- JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL
- JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL
- Uncaught SyntaxError: Unexpected token ILLEGAL【js错误】
- JS提示:Uncaught SyntaxError: Unexpected token ILLEGAL错误的解决方法
- JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL
- JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL
- JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL
- JS提示:Uncaught SyntaxError:Unexpected token ) 错误的解决方法
- JS错误Uncaught SyntaxError: Unexpected token < 分析及解决方法
- 记录js错误:Uncaught SyntaxError: Unexpected token <
- 前端javascript 错误 Uncaught SyntaxError: Unexpected token ILLEGAL
- js里方法调用传参长字符串时为对象或者Uncaught SyntaxError: Unexpected token ILLEGAL
- 学习js,时查看浏览器提示的错误Uncaught SyntaxError: Unexpected token [
- JS页面出现Uncaught SyntaxError: Unexpected token < 错误
- JS缺失错误- Uncaught SyntaxError: Unexpected token <
- JS-我遇到的JS报错:Uncaught SyntaxError: Invalid or unexpected token
- JS异常处理:Uncaught SyntaxError: Unexpected token ) , VM242:1
- js报错,Uncaught SyntaxError: Unexpected token }
- 使用空格时Uncaught SyntaxError: Unexpected token ILLEGAL
- 解决Ajax请求出现Uncaught SyntaxError: Unexpected token : 错误