Cookies用户登录

Document

用户登录

账号:
密码:

 

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<script src="/js/js.cookie.min.js">
</head> 
<h1>用户登录</h1>
    账号:<input id="denglu" type="text"><br>
    密码:<input id="pwd" type="text"><br>
    <input type="checkbox" id="name"><label for="name">保存密码</label><br>
    <input type="button" id="qwe" value="登录">

    <h4 id="h44"></h4>
    <h4 id="h45"></h4>
    <script>
    //获取id var name1 = document.getElementById("name"); var denglu = document.getElementById("denglu"); var pwd = document.getElementById("pwd"); var h44 = document.getElementById("h44"); var h45 = document.getElementById("h45");       //为空的时候 if (denglu.value != "", pwd.value != "", denglu.value != "undefined", pwd.value != "undefined") { name1.checked = true; denglu.value = Cookies.get("zhanghao"); pwd.value = Cookies.get("pwd"); } else { denglu.value = ""; pwd.value = ""; // denglu.value = Cookies.get("zhanghao"); // pwd.value = Cookies.get("pwd"); } name1.addEventListener("click", function () { if (name1.checked) { alert // sessionStorage.setItem("zhanghao", denglu.value); // sessionStorage.setItem("pwd",pwd.value); // sessionStorage["zhanghao"]="denglu.value"; // sessionStorage["pwd"]="pwd.value"; // sessionStorage.zhanghao="denglu.value"; // sessionStorage.pwd="pwd.value"; Cookies.set("zhanghao", denglu.value); Cookies.set("pwd", pwd.value); if (Cookies.get("zhanghao" == undefined), Cookies.get("pwd" == undefined)) { console.log("123"); } else { denglu.value = Cookies.get("zhanghao"); pwd.value = Cookies.get("pwd"); } // console.log("!2312"); } else { Cookies.remove("zhanghao"); Cookies.remove("pwd"); denglu.value = ""; pwd.value = ""; } }, false) var qwe = document.getElementById("qwe"); qwe.addEventListener("click", function () { Cookies.set("zhanghao", denglu.value); Cookies.set("pwd", pwd.value); h44.innerHTML = Cookies.get("zhanghao"); h45.innerHTML = Cookies.get("pwd"); name1.checked; }, false); </script> </body> </html>

  

posted @ 2022-03-02 18:59  33的男孩  阅读(47)  评论(0编辑  收藏  举报