JS获取地址栏参数转换为对象

    function getRequestParams(){var params = {};
        var href = location.href;
        var index = href.indexOf('?');
        if(index !== -1){
            href = href.substring(index + 1);
            var arr = href.split("&");
            var temp;
            for(var i = 0; i < arr.length; i++){
                temp = arr[i].split("=");
                params[temp[0]]=temp[1]
            }
        }
        return params;
    }

 

    function getRequestParams(){
        let params = {};
        let href = location.href;
        var index = href.indexOf('?');
        if(index !== -1){
            href = href.substring(index + 1);
            let arr = href.split("&");
            arr.forEach(item => {
                let temp = item.split("=");
                params[a[0]]=a[1];
            }) 
        }
        return params;
    }

 

posted @ 2022-05-23 11:21  SpringCore  阅读(441)  评论(0编辑  收藏  举报