美文网首页文艺小菜
JS代码URL传中文参数乱码

JS代码URL传中文参数乱码

作者: 文艺小菜 | 来源:发表于2019-01-11 11:59 被阅读14次

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传中文参数乱码

    本文链接:https://www.haomeiwen.com/subject/pptxdqtx.html