利用url传值,获取

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 + "
") test1 = unescape(test1) document.write(test1 + "
")

你可能感兴趣的:(利用url传值,获取)