首页 > 编程语言 > 详细

js获取url参数 数组

时间:2021-02-01 14:44:28      阅读:108      评论:0      收藏:0      [点我收藏+]

function GetRequest() {
    var url = decodeURIComponent(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++) {
            var tempArr = strs[i].split("=");
            // 类型转换
            if (tempArr[1] == ‘true‘) {
                tempArr[1] = true;
            }
            if (tempArr[1] == ‘false‘) {
                tempArr[1] = false;
            }
            if (/^[\d|.]+$/.test(tempArr[1])) {
                tempArr[1] = Number(tempArr[1]);
            }
            // 写入对象
            if (tempArr[0].search(/\[.*]/) == -1) {
                theRequest[tempArr[0]] = tempArr[1];
            } else {
                // 数组
                var key = tempArr[0].replace(/\[.*]/, ‘‘);
                if (!theRequest[key]) {
                    theRequest[key] = [tempArr[1]];
                } else {
                    theRequest[key].push(tempArr[1]);
                }
            }
        }
    }
    return theRequest;
}

js获取url参数 数组

原文:https://www.cnblogs.com/cmtspace/p/14356312.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!