GetUrlParam:获取Url参数,返回一个对象

function GetUrlParam(){    
  let url = document.location.toString();

  let arrObj = url.split("?");

  let params = Object.create(null)

  if (arrObj.length > 1){

    arrObj = arrObj[1].split("&");

    arrObj.forEach(item=>{

      item = item.split("=");

      params[item[0]] = item[1]

    })

  }

  return params;
}
// ?a=1&b=2&c=3 ==> {a: "1", b: "2", c: "3"}
posted @ 2020-01-19 15:24  入坑的H  阅读(781)  评论(0编辑  收藏  举报