1、前端通过 url 传递参数,但是参数又有中文,在下一个页面接受参数的时候中文会乱码
解决方案为:
定义和用法
decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。
语法
decodeURI(URIstring);
具体代码:
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"); });
接受的时候:
var test = window.location.href; var str = test.split("?").pop(); var arrNew = str.split("="); console.log(decodeURI(arrNew[1]));
2、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- 14px; 14px;"> <p class="weui-media-box__desc"><img src="/images/icon_delete.png" alt=""></p> </div> </div>';