检查

来源:2-12 自由编程

今生一坠

2021-09-02 05:50:50

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

        .form{

            width250px;

            line-height40px;

            margin0 auto;

        }

        #sign{

            background-colorgreen;

            color:white;

            border-radius6px;

            width50px;

            height26px;

            border:0;

            margin-left60px;

            margin-right20px;

        }

        #delete{

            background-colorred;

            color:white;

            border-radius6px;

            width50px;

            height26px;

            border:0;

        }

    </style>

</head>

<body>

    <form class='form'>

            <span>用户名:</span>

            <input type="text" placeholder="请输入用户名" id='text'/>

            <br>

            <input type="button" value='登录' id='sign'/>

            <input type="button" value='删除' id='delete'/>

    </form>

    <script type='module'>

        import {SET,GET,DELETEfrom './cookie.js' 

        const signBtn=document.getElementById('sign');

        const deleteBtn=document.getElementById('delete');

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

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

        window.onload=()=>{

            if(GET('username')){

                text.value=GET('username');

            }

        }

        signBtn.addEventListener('click',()=>{

            let value=text.value

            if(!GET('username')){

                SET('username',value,{

                maxAge:7*24*3600

            })

                

            }

        },false)

        deleteBtn.addEventListener('click',()=>{

            DELETE('username')

            text.value=''

        },false)

    </script>

</body>

</html>


写回答

1回答

好帮手慕星星

2021-09-02

同学你好,代码逻辑没问题,但是从cookie.js文件中引入的方法名称与资料中给的不一致

https://img.mukewang.com/climg/61302f4009d6e63a05260042.jpg

建议将自己写的cookie.js代码粘贴上来,老师测试下。

祝学习有愉快!

0

0 学习 · 15276 问题

查看课程

相似问题

请老师检查

回答 1

请老师检查

回答 1

请老师检查

回答 1

老师请检查

回答 1

老师请检查

回答 1