问题遇到的现象和发生背景
通过windows.open进行两个页面之间的传值,但传不过去
问题相关代码,请勿粘贴截图
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
</style>
<body>
<form action="用户名显示.html" method="get">
<span>用户名:</span><input type="text" id="u" /><br>
<span>密码:</span><input type="password" id="p" /><br>
<input type="submit" value="登录" onclick="login()" />
</form>
</body>
<script type="text/javascript">
function login() {
var name = document.getElementById("u").value; /*value把值带入到前面*/
var password = document.getElementById("p").value;
var uname = localStorage.getItem("uname");
var upassword = localStorage.getItem("upassword");
if (name == uname && password == upassword) {
alert("登录成功");
window.opener.document.getElementById("user").innerHTML = uname; /*换名字*/
self.close();
} else {
alert("登录失败");
self.close();
}
}
</script>
</html>
<span id="user">
游客
</span>您好!欢迎来到网上咖啡商城
<a href="登录.html" target="登录.html">[登录]</a>
<script>
function login() {
window.open("登录.html", "", false)
}
function register() {
window.open("注册.html", "", "width=540px,height=540px", false)
}
</script>
<body>
<form action="" method="get">
<span>用户名:</span><input type="text" name="" id="u" value="" /><br>
<span>密码:</span><input type="password" name="" id="p" value="" /><br>
<input type="submit" value="注册" onclick="register()" />
</form>
</body>
<script type="text/javascript">
function register() {
var name = document.getElementById("u").value; /*value把值带入到前面*/
var password = document.getElementById("p").value;
localStorage.setItem("uname", name);
localStorage.setItem("upassword", password);
alert("注册成功");
self.close();
}
</script>
运行结果及报错内容
登录页面内的用户名和密码都是随便改,就是用户名不在主页显示
我的解答思路和尝试过的方法
我想要达到的结果
学校不让用什么数据库啥的,只能用js去写,麻烦各位了