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