使用了sessionStorage
技术,类比cookie
和localStorage
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册</title>
</head>
<body>
<form method="post">
<label for="msg">请输入姓名:</label><input type="text" id="msg">
<input type="button" id="btn" value="下一页" onclick="next()">
</form>
<script>
window.onload = function () {
let msg = sessionStorage.getItem("msg");
let toMsg = document.getElementById("msg");
toMsg.value = msg;
}
function next() {
let msg = document.getElementById("msg");
sessionStorage.setItem("msg", msg.value);
window.location.href = "register2.html";
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册2</title>
</head>
<body>
<form method="post">
<label for="msg2">请输入性别:</label><input type="text" id="msg2">
<input type="button" id="btn" value="下一页" onclick="last()">
</form>
<script>
window.onload = function () {
let msg2 = sessionStorage.getItem("msg2");
let toMsg = document.getElementById("msg2");
toMsg.value = msg2;
}
function last() {
let msg2 = document.getElementById("msg2");
sessionStorage.setItem("msg2", msg2.value);
window.location.href = "register.html";
}
</script>
</body>
</html>