JavaScript获取地址栏的参数!

第一种方式:手动解析 “location”对象

console.log(window.location);

使用这个对象做跳转:

window.location.href="";

第二种方式:正则解析URL地址

function GetQueryString(name){
  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if(r!=null)return unescape(r[2]);
   return null;
}
// 调用方法
alert(GetQueryString('参数1'));
alert(GetQueryString('参数2'));

 

posted @ 2017-10-12 09:24  帅到要去报警  阅读(157)  评论(0编辑  收藏  举报