123456789101112131415161718192021222324252627282930 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <h1>cookie</h1>
- <script>
- // document.cookie cookie 操作防范
- document.cookie = 'name=张三';
- document.cookie = 'age=18';
- document.cookie = 'sex=男';
- // 设置cookie 过期时间
- // var now = new Date();
- // // setDate 设置日期
- // now.setDate(now.getDate() + 1);
- // console.log(now)
- // // toUTCString() 转换为UTC格式的日期字符串
- // document.cookie = "name=张三;expires="+ now.toUTCString();
- // 读取cookie
- console.log(document.cookie)
- </script>
- </body>
- </html>
|