JS代码URL传中文参数乱码

1.传值
window.location.href ='html/search.html?search='+escape(val);

    加上escape()

2.接收

 unescape(getUrlParms("productName"));

3.获取传值

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

你可能感兴趣的:(JS代码URL传中文参数乱码)