<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
账号:<input>
密码:<input>
记住密码:<input type="checkbox">
<button οnclick="set()">登录</button>
<script>
var user = document.getElementsByTagName("input")[0],
pass = document.getElementsByTagName("input")[1],
check = document.getElementsByTagName("input")[2],
loUser = localStorage.getItem("user") || "";
loPass = localStorage.getItem("pass") || "";
user.value = loUser;
pass.value = loPass;
if(loUser !== "" && loPass !== ""){
check.setAttribute("checked","");
}
function set(){
if(check.checked){
localStorage.setItem("user",user.value);
localStorage.setItem("pass",pass.value);
}else{
localStorage.setItem("user","");
localStorage.setItem("pass","");
}
console.log(localStorage.getItem("user"));
console.log(localStorage.getItem("pass"));
}
</script>
</body>
</html>
localStorage本地存储
最新推荐文章于 2024-09-12 13:49:04 发布