动态

详情 返回 返回

封裝一個方法,獲取頁面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.