url 傳參數時出現中文亂碼

一、前端經過 url 傳遞參數,可是參數又有中文,在下一個頁面接受參數的時候中文會亂碼html

解決方案爲:  前端

  定義和用法es6

decodeURI() 函數可對 encodeURI() 函數編碼過的 URI 進行解碼。json

語法app

decodeURI(URIstring);函數

具體代碼:ui

var name = encodeURI(json.cCusAbbName); 
                    var address = encodeURI(json.cCusAddress); 
                    $.alert("信息保存成功", "提示", function() {
                        window.open("/order/detail/addOrder?"+json.cCusCode+"="+name+"="+json.cCusHand+"="+address+"="+json.cCusPhone,"_self");
                    });

接受的時候:this

var test = window.location.href;
        var str = test.split("?").pop();
        var arrNew = str.split("=");
console.log(decodeURI(arrNew[1]));

 二、es6 新拼接代碼格式編碼

 var html =  '<div class="weui-media-box weui-media-box_appmsg " dataId="'+decodeURI(arrNew[0])+'">\
                    <div class="weui-media-box__hd width50">\
                        <img class="weui-media-box__thumb" src="../../../images/people_pic.png" alt="">\
                    </div>\
                    <div class="weui-media-box__bd">\
                        <h4 class="weui-media-box__title">'+decodeURI(arrNew[1])+'</h4>\
                        <p class="weui-media-box__desc">'+decodeURI(arrNew[2])+'</p>\
                    </div>\
                    <div class="weui-media-box__bd" onclick="deteleUser(this)" style="max-width: 14px;width: 14px;">\
                        <p class="weui-media-box__desc"><img src="/images/icon_delete.png" alt=""></p>\
                    </div>\
                </div>';
相關文章
相關標籤/搜索