動態

詳情 返回 返回

封裝一個方法,獲取頁面url中的參數值? - 動態 詳情

封裝一個方法獲取頁面url參數,可作為框架基礎方法使用:

//獲取url參數; 正則獲取url參數,包含hash[#]和search[?]兩種通用
export function getUrlQueryByName(param) {
  const reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
  const r =
    window.location.search.substr(1).match(reg) ||
    window.location.hash
      .substring(window.location.hash.search(/\?/) + 1)
      .match(reg);
  if (r != null) {
    return decodeURIComponent(r[2]);
  }
}

卡布奇諾今猶在,不見當年倒茶人~😌

user avatar grewer 頭像 haoqidewukong 頭像 nihaojob 頭像 anchen_5c17815319fb5 頭像 Dream-new 頭像 dunizb 頭像 zzd41 頭像 imba97 頭像 zhulongxu 頭像 wmbuke 頭像 DingyLand 頭像 romanticcrystal 頭像
點贊 112 用戶, 點贊了這篇動態!
點贊

Add a new 評論

Some HTML is okay.