利用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 + "<br />")
            test1 = unescape(test1)
            document.write(test1 + "<br />")
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容