获取地址栏参数

/* *****************************
* 获取参数值
* @param name 参数名称
* @returns 参数值
***************************** */
 
CloudShareCommon.prototype.getQueryString = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    var context = "";
    if (r != null)
        context = r[2];
    reg = null;
    r = null;
    return context == null || context == "" || context == "undefined" ? "" : context;
};    
 
--------------------------------------------------------------------------------------------------------------------
//获取URL参数
function getQueryString(name) {
    var url = window.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]] = decodeURI(strs[i].split("=")[1]);
        }
    }
return theRequest[name];
}    
 
--------------------------------------------------------------------------------------------------------------------
var a="https://www.baidu.com?user_id=324300147&mobile=15802038598"

function parseQueryString(url) {
    var json = {};
    var arr = url.substr(url.indexOf('?') + 1).split('&');
    arr.forEach(function(item) {
        var tmp = item.split('=');
        json[tmp[0]] = tmp[1];
    })
    return json;
}

alert(parseQueryString(a).mobile);
原文地址:https://www.cnblogs.com/queende7/p/8668892.html