获取URL参数(整理常用)

1、获取某一个参数

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    var context = "";
    if (r != null)
         context = decodeURIComponent(r[2]);
    reg = null;
    r = null;
    return context == null || context == "" || context == "undefined" ? "" : context;
}
console.log(GetQueryString("name"));

2、获取所有的参数

function getQueryStriongArgs(){
        var qs = (location.search.length>0?location.search.substring(1):""),
            args = {},
            items = qs.length ? qs.split("&"):[],
            item = null,
            name = null,
            value= null,
            i = 0,
            len = items.length;
            for(i = 0;i

你可能感兴趣的:(获取URL参数(整理常用))