解決JS中取URL地址中的參數中文亂碼


GET請求會將中文編碼,如果取出亂碼的話,應該進行解碼操作,

下面的函數是獲取指定參數名的參數值,參數值可是中文、英文。

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeURIComponent(r[2]); return null; }

 

注意: 需要在頁面head中添加下面這個meta標簽

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 


免責聲明!

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



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