[BOM]分解url参数

分解页面 url 传入参数

转载: 来自https://www.jianshu.com/p/6dd040f6800d

    function init_params() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
           var str = url.substr(1);
           strs = str.split("&");
           for(var i = 0; i < strs.length; i ++) {
              theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
           }
        }
        return theRequest;
    }

    var params = init_params()
    console.log('params', params)

 

posted @ 2023-01-06 11:25  夕苜19  阅读(18)  评论(0编辑  收藏  举报