正则获取url中对应参数的值

 js:
 
var str= this.getParameter("bucketName");
alert(str);
打印结果:20200924
 
 
 
 
getParameter(name) {
  this.url = "http://localhost:9701/bs/api/v1/minio/buckets/file/share?bucketName=20200924&fileName=dd.jpg"
 
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构建一个含有目标参数的正则表达式对象
      var r = this.url.substr(1).match(reg); //匹配目标参数,url
      if (r != null) {
        //return unescape(r[2]); //返回参数值,参数值为中文时可能会乱码
  return decodeURI(r[2]); //返回参数值。游览器默认使用的encodeURI进行编码,所以用decodeURI解码避免乱码
      }
      return null;
    },
posted @ 2020-09-29 15:01  逸凨  阅读(532)  评论(0编辑  收藏  举报