美文网首页
利用url传值,获取

利用url传值,获取

作者: wyq_0bed | 来源:发表于2017-07-18 11:02 被阅读0次

a.html页面中

 var count = 'asd',
            name = 'wyq';
            $("#btn").click(function() {
                window.location.href = 'a.html' + '?cont=' + count + '&name=' + name;
            })

b.html页面中

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

unescape() 函数可对通过 escape() 编码的字符串进行解码。

            var test1 = "Visit W3School!"
            test1 = escape(test1)
            document.write(test1 + "<br />")
            test1 = unescape(test1)
            document.write(test1 + "<br />")

相关文章

网友评论

      本文标题:利用url传值,获取

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