js 获取URL中参数

function getQueryString() {
    var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+", "g"));
    if (result == null) {
        return "";
    }

    for (var i = 0; i < result.length; i++) {
        result[i] = result[i].substring(1);
    }

    return result;
}

//根据QueryString参数名称获取值
function getQueryStringByName(name) {
    var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }

    return result[1];
}

 

posted @ 2017-08-24 11:45  小水皮  阅读(237)  评论(0编辑  收藏  举报