function querys(url){ var result = {},keyReg = /(\?(.*?)=|&(.*?)=)/g,valReg = /=(.*?)&/g,urls = url ? (url + "&") : "",keys = urls.match(keyReg) || [],vals = urls.match(valReg) || []; for (var i = 0,size = keys.length; i < size; i++) { result[keys[i].replace(/(\?|=|&)/g,'')] = vals[i].replace(/(=|&)/g,''); } return result; } console.log(querys("https://www.baidu.com/s?wd=test&rsv_spt=")) //输出: {wd:"test",rsv_spt:""}