Location对象的查询字符方法实现

function getQueryStringArgs(){
        /*如果location.search有则删除第一个字符,并返回删除后的字符串*/
        var gs = (location.search.length) ? location.search.sustring(1) : '',
        /*定义返回的对象*/
        args = {},
        /*如果gs.length非0,则返回以&为分隔符的数组*/
        items = gs.length ? gs.split('&') : [],
        /*item为数组*/
        item = null,
        /*name为查询的字符的名字*/
        name = null,
        /*name为查询的字符的内容*/
        value = null,
        i = 0,
        /*数组的长度*/
        len = items.length;

        for (;i<len ;i++ )
        {    /*返回items数组的每一项以‘=’为分割的数组*/
            item = items[i].split('=');
            /*URI 解码item[0]是name*/
            name = decodeURIComponent( item[0] );
            /*URI 解码item[0]是value*/
            value = decodeURIComponent( item[1] );
            /*name.length不为空*/
            if (name.length)
            {
                /*添加属性*/
                args[name] = value;
            }
        }
        /*返回对象*/
        return args;
    }
原文地址:https://www.cnblogs.com/jokes/p/9403379.html