url传中文参数乱码问题

//发出请求页面(编码 encodeURI)
window.location.href="index.html?name="+encodeURI(encodeURI(name));

//接受参数页面(解码 decodeURI)
//获取URL地址参数
function GetQueryString(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)
        return  unescape(r[2]);
    return null;
}
$(".head-title").text(decodeURI(decodeURI(GetQueryString('name'))))

猜你喜欢

转载自www.cnblogs.com/dxt510/p/9149254.html