查询字符串函数

function getQueryStringArgs() {
    if(!location.search.length > 0) {
        return {};
    }

    var args = {},
        items = location.search.slice(1).split('&'),
        name,
        value;
    
    items.forEach(function(item) {
        arr = item.split('=');
        name = decodeURIComponent(arr[0]);
        value = decodeURIComponent(arr[1]);

        if (name) {
            args[name] = value;
        }
    });

    return args;
}

你可能感兴趣的:(查询字符串函数)