获取多个url参数
getUrlParam:function (name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)
return unescape(r[2]);
return null;
}
获取单个url参数
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];
}
}
}
修改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)
微信扫描下方的二维码阅读本文