js url参数解析获取

function get_url_parm_list(str){
var params=str.substr(str.indexOf('?')+1);
var param_list=[];
while(params.indexOf('=')!=-1){
var ind=params.indexOf('=');
var k=params.substr(0,ind);
var sp=params.indexOf('&');
if(sp==-1){
var v=params.substr(ind+1);
params='';
}else{
var v=params.substr(ind+1,sp-(ind+1));
params=params.substr(sp+1);
}
var obj={
key:k,
val:v
}
param_list.push(obj);
}
return param_list;
}
var url='https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&ch=1&tn=98010089_dg&wd=%E5%8D%9A%E5%AE%A2%E5%9B%AD&oq=linux%2520%25E6%2589%258B%25E5%258A%25A8%25E9%2587%258A%25E6%2594%25BEcached&rsv_pq=ac13c90200032567&rsv_t=7c77pw33dzPw4VnWMcrdFmpfrTclrhSG4CYm5J%2BBqNths9Ca3i1Mjko4Tbn3e%2ByDVYc&rqlang=cn&rsv_enter=1&rsv_sug3=8&rsv_sug1=8&rsv_sug7=101&rsv_sug2=0&inputT=3762&rsv_sug4=3763';
get_url_parm_list(url);

结果为js数组,[{key:'key',val:'val'},...]

上一篇:Golang 新手可能会踩的 50 个坑【转】


下一篇:Struts2的OGNL表达式语言