Uncaught SyntaxError: Invalid Unicode escape sequence異常處理

  今天碰到一個問題,頁面報錯:Uncaught SyntaxError: Invalid Unicode escape sequencejson

,{index:'operate',name:'operate',label:'<s:text name="com.vrv.cems.ptp.installSoft.operate"></s:text>',width:getPerWidth(0.1), formatter:function(value,rec,index){ return '<img onclick="uninst(this,\''+index.uninstallMode+'\',\''+index+'\')" title="<s:text name="cems.unInstall"></s:text>" src="${basePath}/images/ptp/delete.png" width="16px" height="16px" style="cursor:pointer;">'; //return '<img onclick="uninst(this,\''+index.uninstallMode.replace(/\\/g,"/")+'\',\''+index+'\')" title="<s:text name="cems.unInstall"></s:text>" src="${basePath}/images/ptp/delete.png" width="16px" height="16px" style="cursor:pointer;">';
 } }

  index.uninstallMode是一個軟件的路徑,this

  點擊按鈕,有時候就會出現所報錯誤,可是奇怪的是有的會報,有的不會報錯spa

  緣由估計就是反斜槓在js裏面是轉義符致使的,以下:3d

  正常的話應該如此:code

  因此考慮到的解決方案就是將一個反斜槓換成兩個反斜槓,(這樣後臺返回json串時就要加4條反斜槓),以下果真正常執行:orm

  固然換成正斜槓也能夠。blog

  因此將代碼改成下面:get

,{index:'operate',name:'operate',label:'<s:text name="com.vrv.cems.ptp.installSoft.operate"></s:text>',width:getPerWidth(0.1), formatter:function(value,rec,index){ //return '<img onclick="uninst(this,\''+index.uninstallMode+'\',\''+index+'\')" title="<s:text name="cems.unInstall"></s:text>" src="${basePath}/images/ptp/delete.png" width="16px" height="16px" style="cursor:pointer;">';
        return '<img onclick="uninst(this,\''+index.uninstallMode.replace(/\\/g,"/")+'\',\''+index+'\')" title="<s:text name="cems.unInstall"></s:text>" src="${basePath}/images/ptp/delete.png" width="16px" height="16px" style="cursor:pointer;">'; } }
相關文章
相關標籤/搜索