cookie小案例30天内免登录

30天内免登陆 cookie小案例

原生js,$在machine文件中封装,可直接使用,cookie也封装在其中
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
     
     
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div id="box">
        <div>账号<input type="text" id="username"></div>
        <div>密码<input type="password" id="password"></div>
        <div><input type="checkbox" id="che">30天内免登录</div>
        <div><button id="login">登录</button></div>
    </div>
    <!-- machine.js为封装的cookie等  -->
    <script src="machine.js"></script>
    <script>
        $("#login").onclick = function() {
     
     
            if ($("#che").checked) {
     
     
                cookie.set("username", $("#username").value, '2021-02-08');
                cookie.set("password", $("#password").value, 30)
            }
        }

        if (cookie.get("username") && cookie.get("password")) {
     
     
            $("#username").value = cookie.get("username")
            $("#password").value = cookie.get("password")
        }
    </script>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/HXX548888/article/details/112391556
今日推荐