检查
来源: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{
width: 250px;
line-height: 40px;
margin: 0 auto;
}
#sign{
background-color: green;
color:white;
border-radius: 6px;
width: 50px;
height: 26px;
border:0;
margin-left: 60px;
margin-right: 20px;
}
#delete{
background-color: red;
color:white;
border-radius: 6px;
width: 50px;
height: 26px;
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,DELETE} from './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文件中引入的方法名称与资料中给的不一致

建议将自己写的cookie.js代码粘贴上来,老师测试下。
祝学习有愉快!