location查询字符串解析

function getQueryStringArgs() {
    //取得查询字符串并去掉开头的问号
    var qs = (location.search.length >0? location.search.substring(1) : "");

    //保存数据的对象
    var args= {};

    //取得每一项
    var items = qs.split("&");
    var item = null,
        name = null,
        value = null;

    //逐个将每一项添加到args对象中
    for (var i=0; i<items.length; i++) {
        item = items[i].split("=");
        name = decodeURIComponent(item[0]);//解码名称
        vale = decodeURIComponent(item[1]);//解码值
        args[name] = value;
    }

    return args;
}

 

posted @ 2013-07-10 16:19  金帛  阅读(331)  评论(0编辑  收藏  举报