首页 > 代码库 > URL参数转换对象

URL参数转换对象

    var parseQueryString = function (url) {        var reg_url = /^[^\?]+\?([\w\W]+)$/,                reg_para = /([^&=]+)=([\w\W]*?)(&|$)/g, //g is very important                arr_url = reg_url.exec(url),                ret = {};        if (arr_url && arr_url[1]) {            var str_para = arr_url[1], result;            while ((result = reg_para.exec(str_para)) != null) {                ret[result[1]] = result[2];            }        }        return ret;    }
  //使用方法:
var url = "key0=0&key1=1&key2=&key3=http://www.g.cn?a=1&&b=2"; var obj = parseQueryString(url); console.dir(obj);

 

 

技术交流QQ群:15129679

URL参数转换对象