我有一个要求用户输入以下内容的 html 页面
- 用户名和密码点击提交重定向到load.html
- 没有输入,但是点击生成ID,自动重定向到load.html
- 输入唯一ID,并重定向到load.html
但是,我知道我需要存储用户名和密码或唯一 ID。我试过以下
var user = document.getElementById("username");
var password = document.getElementById("password");
localStorage.user = user;
localStorage.password = password;
我尝试通过以下方式在 load.html 中使用它
var user = localStorage.user;
但我不知道如何使用变量获取用户输入。另外有没有一种方法可以使用函数而不是表单重定向到另一个网页?
提前致谢
function connector_id()
{
var id_ =document.getElementById("id")
id_.innerHTML=Math.floor((Math.random()*100000000)+100000000);
return id_;
}
var user = document.getElementById("username");
var password;
localStorage.user = user;
localStorage.password = password;
</script>
<form action = "load.html" method = "post">
Username: <input type = "text" name = "username" id="username"/>
<br />
Password: <input type = "password" name = "pass" />
<br />
<input type = "submit" value = "Submit">
</form>
<p id ="id"></p>
<button onclick="connector_id()">generate</button>
</p>
<form action = "load.html" method = "post">
ID: <input type = "text" name = "username" />
<input type = "submit" value = "Submit">
</form>