乐趣区

关于javascript:如何清除url中指定参数并返回url

export function deleteUrlQueryByName(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 window.location.href.replace(`${param}=${decodeURIComponent(r[2])}`,
      '',
    );
  }
  return window.location.href;
}
退出移动版