js给url字符串添加参数


changeZhiboUrl(url){
    //转换跳转直播的url
      let str1 = this.addOrgToUrl(url,'u_code',this.getLoginAfterData.id);
      let str2 = this.addOrgToUrl(str1,'authRight',localStorage.getItem('meetingManager_authRight'));
      return str2;
    },
    addOrgToUrl(url,paramName,replaceWith){
    //url字符串添加参数
    //url:路径地址 paramName:参数名 replaceWith:参数值
      if (url.indexOf(paramName) > -1) {
          var re = eval('/(' + paramName + '=)([^&]*)/gi');
          url = url.replace(re, paramName + '=' + replaceWith);
      } else {
          var paraStr = paramName + '=' + replaceWith;

          var idx = url.indexOf('?');
          if (idx < 0)
              url += '?';
          else if (idx >= 0 && idx != url.length - 1)
              url += '&';
          url=url + paraStr;
      }
      return url;
    },

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM