请老师检查
<!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 { margin: 0 auto; width: 250px; } input { margin: 5px; } </style> </head> <body> <form action="" id="form"> <label for="">用户名:</label> <input type="text" name="text" placeholder="请输入用户名" /> <input type="button" name="login" value="登陆" /> <input type="button" name="delete" value="删除" /> </form> <script type="module"> import { set, get, remove } from './js/cookie.js'; const form = document.getElementById('form'); const loginBtn = form.login; const deleteBtn = form.delete; if (get('username')) { form.text.value = get('username'); } loginBtn.onclick = e => { e.preventDefault(); set('username', form.text.value, { maxAge: 60 * 60 * 24 * 7, }); window.location = '../1.html'; }; deleteBtn.onclick = () => { remove('username'); window.location = '../1.html'; }; </script> </body> </html>
我的电脑是Mac Book,使用的浏览器是Chrome版本 100.0.4896.127,当我没有设置maxAge时,关闭重新打开浏览器,cookie依然存在呢?
8
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星