JS 获取 URL 中 GET 参数的值(正则法和 location.search 法)

正则法

location.search 法

function getSearch() {
  let url = location.search;
  let theRequest = new Object();

  if (url.indexOf("?") != -1) {
    let str = url.substr(1);
    strs = str.split("&");

    for(var i = 0; i < strs.length; i ++) {
      theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
  }

  return theRequest;
}