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
时间: 2024-10-10 07:27:41