Stories

Detail Return Return

封裝一個方法,獲取頁面url中的參數值? - Stories Detail

封裝一個方法獲取頁面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 Avatar haoqidewukong Avatar nihaojob Avatar anchen_5c17815319fb5 Avatar Dream-new Avatar dunizb Avatar zzd41 Avatar imba97 Avatar zhulongxu Avatar wmbuke Avatar DingyLand Avatar romanticcrystal Avatar
Favorites 112 users favorite the story!
Favorites

Add a new Comments

Some HTML is okay.