正则匹配url参数

function getQueryObject(url) {
  url = url == null ? window.location.href : url;
   var search = url.substring(url.lastIndexOf("?") + 1);
   var obj = {};     
   var reg = /([^?&=]+)=([^?&=]*)/g;
   search.replace(reg, function (rs, $1, $2) {
     var name = decodeURIComponent($1);
     var val = decodeURIComponent($2);
     val = String(val);
     obj[name] = val;
  
return rs; });
return obj;
}
//该方法的目的是对 URI 进行完整的编码,因此对以下在 URI 中具有特殊含义的 ASCII 标点符号,encodeURI() 函数是不会进行转义的:;/?:@&=+$,# //decodeURIComponent($1);//URI解码 encodeURIComponent加密(所有的)

 

posted @ 2017-11-25 14:22  Tim.Arrow  阅读(3426)  评论(0编辑  收藏  举报