Url参数获取和更改
Url参数获取和更改
Lieme获取多个url参数
1 | getUrlParam:function (name){ |
getUrlParam:function (name){
var params = location.search.substr(1);
var ArrParam = params.split(‘&’);
for(var i = 0; i <ArrParam.length; i ++){
if(ArrParam[i].split(‘=’)[0] == name){
return ArrParam[i].split(‘=’)[1];
}
}
}
1 | ##### 修改url地址 |
changeURLPar:function(url,arg,arg_val){
var pattern=arg+’=([^&])’;
var replaceText=arg+’=’+arg_val;
if(url.match(pattern)){
var tmp=’/(‘+ arg+’=)([^&])/gi’;
tmp=url.replace(eval(tmp),replaceText);
return tmp;
}else{
if(url.match(‘[?]’)){
return url+’&’+replaceText;
}else{
return url+’?’+replaceText;
}
}
return url+’\n’+arg+’\n’+arg_val;
}
//用法
var txt = window.location.href
changeURLPar(txt, ‘type’, 99)
```