做这样的事情:[第1页]-
<script>
function assignwebStorage()
{
var a=document.getElementsByTagName("input")[0].value;
var b=document.getElementsByTagName("input")[1].value;
if((a!=null&&a!="")&&(b!=null&&b!=""))
{
localStorage.username=a;
localStorage.password=b;//aware
}
}
</script>
<form action="page2.htm" onsubmit="assignwebStorage()">
Username:<input type="text"></input><br>
Password:<input type="password"></input><br>
<input type="submit" value="Proceed"></input></form>
[第2页]-
<script>
if(typeof localStorage.username=="undefined" && typeof localStorage.password=="undefined")
{
document.write("<form action='page3.htm' onsubmit='assignvalue()'>Username:<input type='text'></input><br>Password:<input type='password'></input><br><input type='submit' value='Submit'></input></form>");
function assignvalue()
{
localStorage.username=document.getElementsByTagName("input")[0].value;
localStorage.password=document.getElementsByTagName("input")[1].value;
}
}
else
{
window.location.replace("page3.htm")
}
</script>
[第 3 页]-
<body style="background:black">
<script>
//use webStorage variables anywhere but after that
delete localStorage.username;
delete localStorage.password;
//if any time user directly opens file 2 without opening file1
</script>
</body>
它肯定会解决你的问题。