Cookie的封装-2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Cookie的封装</title> </head> <body> <button id="cn">中文</button> <button id="en">英文</button> <script type="module"> import{set,get,remove} from './js/cookie.js'; const cnBtn =document.getElementById('cn'); const enBtn =document.getElementById('en'); cnBtn.addEventListener( 'click', ()=>{ set('language','cn',{ maxAge: 30* 24 *3600 }); window.location='./index.html' }, false ); enBtn.addEventListener( 'click', ()=>{ set('language','en',{ maxAge: 30* 24 *3600 }); window.location='./index.html' }, false ); </script> </body> </html>
Cookie 的注意事项
前后端都可以写入和获取Cookie
Cookie有数量限制
每一个域名下的Cookie数量有限
当超过单个域名限制之后,再设置Cookie,浏览器就会清除以前设置的Cookie
Cookie由数量大小
每一个Cookie的存储容量很小,最多只有4KB左右
标签:set,封装,cn,maxAge,Cookie,注意事项 From: https://www.cnblogs.com/x3449/p/17241220.html