麻烦老师检查作业,谢谢

来源:2-12 自由编程

叫我丽红

2021-08-25 11:38:11

<!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>

    <style>

        *{

            margin0;

            padding0;

        }

        .list{

            text-aligncenter;

            

            

        }

        .list p{

            font-size18px;

            margin-bottom10px;

            

        }

        .list .load{

            width40px;

            height30px;

            background-colorgreen;

            font-size16px;

            colorwhite;

            border-radius20%;

            bordernone;

            margin-right20px;

            line-height30px;

            

            

        }

        .list .delete{

            width40px;

            height30px;

            background-colorred;

            font-size16px;

            colorwhite;

            border-radius20%;

            bordernone;

            line-height30px;

        } 

        

       

    </style>

</head>

<body>

    <!-- 书写form表单结构 -->

    <form  class="list" action="" method="get">

        <p>

            用户名:<input type="text" id="username" placeholder="请输入用户名">

        </p>

        <button class="load" type="submit" id="load">登录</button>

        <button class="delete" type="submit" id="del" >删除</button>

    </form>

    <script type="module">

        import {set,get,remove} from './cookie.js';

        // 获取输入框和按钮元素

        const username = document.getElementById('username');

        const load = document.getElementById('load');

        const del = document.getElementById('del');

        // 获取cookie,判断cookie是否存在,存在时候,设置输入框的值获取的cookie值

        if(document.cookie !==""){

            username.value = get ("username");

        }

        del.addEventListener(

            "click",

            ()=>{

                remove("username");

            },

            false

        );

        load.addEventListener(

            "click",

            ()=>{

                set("username",username.value,{

                    maxAge:7*24*3600,

                });

            },

            false

        );

    </script>


    

</body>

</html>


写回答

1回答

好帮手慕久久

2021-08-25

同学你好,代码是对的,很棒!

祝学习愉快!

0

0 学习 · 15276 问题

查看课程