麻烦老师检查作业,谢谢
来源: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>
*{
margin: 0;
padding: 0;
}
.list{
text-align: center;
}
.list p{
font-size: 18px;
margin-bottom: 10px;
}
.list .load{
width: 40px;
height: 30px;
background-color: green;
font-size: 16px;
color: white;
border-radius: 20%;
border: none;
margin-right: 20px;
line-height: 30px;
}
.list .delete{
width: 40px;
height: 30px;
background-color: red;
font-size: 16px;
color: white;
border-radius: 20%;
border: none;
line-height: 30px;
}
</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
同学你好,代码是对的,很棒!
祝学习愉快!
相似问题