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

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

    javascript中文url亂碼怎么辦

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

    javascript中文url亂碼怎么辦

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

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

    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();">點(diǎn)擊測(cè)試</p>  <script>     function send(){         var url = "test02.html";         var userName = $("#userName").html(); //        window.open(encodeURI(url + "?userName=" + userName));     //encodeURI針對(duì)整個(gè)參數(shù)進(jìn)行編碼         window.open(url + "?userName=" + encodeURIComponent(userName));  //encodeURIComponent針對(duì)單個(gè)參數(shù)進(jìn)行編碼      } </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針對(duì)整個(gè)參數(shù)進(jìn)行解碼     $("#userName").html(decodeURIComponent(userName));   //decodeURIComponent針對(duì)單個(gè)參數(shù)進(jìn)行解碼 //    $("#userName").html(userName); </script>  </body> </html>

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

    簡(jiǎn)單的分享就到這里,如有疑問(wèn),歡迎留言~

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

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