亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    javascript中文url亂碼怎么辦

    針對中文亂碼問題,最主要是通過(encodeURI,decodeURI),(encodeURIComponent,decodeURIComponent)兩種方法進行參數(shù)的編碼以及解碼工作,其中前者最主要針對的是整個url參數(shù)。

    javascript中文url亂碼怎么辦

    本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

    在日常開發(fā)當(dāng)中,我們可能遇到要將某個頁面的參數(shù)通過url鏈接拼接的方式傳遞到另一個頁面當(dāng)中,在另一個頁面當(dāng)中進行使用,如果傳輸過去的是中文,那么可能會遇到中文亂碼問題,那么該如何來解決呢?

    javascript中文url亂碼怎么辦

    javascript中文url亂碼怎么辦

    <!--test01.html-->  <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Title</title>     <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script> </head> <body>  <p id="userName">你好明天</p>  <p οnclick="send();">點擊測試</p>  <script>     function send(){         var url = "test02.html";         var userName = $("#userName").html(); //        window.open(encodeURI(url + "?userName=" + userName));     //encodeURI針對整個參數(shù)進行編碼         window.open(url + "?userName=" + encodeURIComponent(userName));  //encodeURIComponent針對單個參數(shù)進行編碼      } </script>  </body> </html>
    <!--test02-->  <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Title</title>     <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script> </head>  <body>  <p id="userName"></p>  <script>     var urlinfo = window.location.href;//獲取url     var userName = urlinfo.split("?")[1].split("=")[1];//拆分url得到”=”后面的參數(shù) //    $("#userName").html(decodeURI(userName));          //decodeURI針對整個參數(shù)進行解碼     $("#userName").html(decodeURIComponent(userName));   //decodeURIComponent針對單個參數(shù)進行解碼 //    $("#userName").html(userName); </script>  </body> </html>

    針對中文亂碼問題,最主要是通過(encodeURI,decodeURI),(encodeURIComponent,decodeURIComponent)兩種方法進行參數(shù)的編碼以及解碼工作,其中xxxxURI最主要針對的是整個url參數(shù),xxxxURIComponent針對的是單個url參數(shù);

    簡單的分享就到這里,如有疑問,歡迎留言~

    【推薦學(xué)習(xí):javascript高級教程】

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號