JavaScript 查询字符串函数 - acwong00/blog GitHub Wiki

function getQueryStringArgs() {
    // 取得查询字符串并去掉开头的问号
    var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
    // 保存数据对象
    args = {},
    // 取得每一项
    items = qs.length ? qs.split("&") : [],
    item = null,
    name = null,
    value = null,
    // for循环中使用
    i = 0,
    len = items.length;
    
    for (i=0; i< len; i++) {
        item = items[i].split("=");
        name = decodeURLComponent(item[0]);
        value = decodeURLComponent(item[1]);
    
        if (name.length) {
            args[name] = value;
        }
    }
        return args;
}