久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

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

      javascript中文url亂碼怎么辦

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

      javascript中文url亂碼怎么辦

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

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

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

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

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

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