JS静态页面传值

一、url传值

1、页面跳转传值
url = "Read.htm?username=lanjingjing&sex=female";
location.href=url;
 
2、新的页面进行解析
var url=location.search;
var Request = new Object();
if(url.indexOf("?")!=-1)
 {
   var str = url.substr(1) //去掉?号15   strs = str.split("&");
   for(var i=0;i<strs.length;i++)
  {
      Request[strs[i ].split("=")[0]]=unescape(strs[ i].split("=")[1]);
   }
 }
 alert(Request["username"])
 alert(Request["sex"])
 

二、存入Cookie

跳转前存入setCookie('username','baobao')
新页面getCookie("baobao")
 

三、本地存储(原理与session一样)

跳转前 localStorage.name = document.all.username.value;
跳转后 localStorage["name"];
原文地址:https://www.cnblogs.com/CatcherLJ/p/11176540.html