利用replace转化地址栏:
var url='https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=js%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F&oq=js%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%20kongge&rsv_pq=e63baa94000c303c&rsv_t=2200EoMMe0fGnSJlPpijBDY2Ww1CAkUxvT8jCE2Bif1gXLJ%2Btzixfz%2BAtLE&rsv_enter=1&inputT=294&rsv_sug3=56&rsv_sug1=15&rsv_sug7=100&rsv_sug2=0&rsv_sug4=772&rsv_sug=2'; //解析模拟地址栏 // var url = location.search.substr(1); //这是截取地址栏的情况下,“?”问号以后的内容 var param = {}; url.replace(/([^?&]+)=([^?&]+)/g, function(s, v, k) { console.log('这个是选出a=b是:'+s+',\n这个是键是:'+v+',\n这个是值是:'+k+'。'); param[v] = decodeURIComponent(k);//解析字符为中文 return k + '=' + v; }); console.log(param); /*输出结果为: *f: "8" *ie: "utf-8" *inputT: "294" *oq: "js正则表达式 kongge" *rsv_bp: "1" *rsv_enter: "1" *rsv_idx: "1" *rsv_pq: "e63baa94000c303c" *rsv_sug: "2" *rsv_sug1: "15" *rsv_sug2: "0" *rsv_sug3: "56" *rsv_sug4: "772" *rsv_sug7: "100" *rsv_t: "2200EoMMe0fGnSJlPpijBDY2Ww1CAkUxvT8jCE2Bif1gXLJ+tzixfz+AtLE" *tn: "baidu" *wd: "js正则表达式" */