Uncaught SyntaxError: Invalid Unicode escape sequence異常處理


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

,{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是一個軟件的路徑,

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

  原因估計就是反斜杠在js里面是轉義符導致的,如下:

  正常的話應該如此:

  所以考慮到的解決方案就是將一個反斜杠換成兩個反斜杠,(這樣后台返回json串時就要加4條反斜杠),如下果然正常執行:

  當然換成正斜杠也可以。

  所以將代碼改為下面:

,{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;">'; } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM