PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > JavaScript教程 > 正文

    JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL解决方法

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:JS错误:Uncaught SyntaxError: Unexpected token ILLEGAL解决方法
    $('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动态添加数据的时候 尤其注意‘  ”有时还需要转义。
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-69-1196-1.html
    相关热词搜索: