| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 | 
							- <!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>
 
- </head>
 
- <body>
 
-   <script>
 
-     /* cookie 浏览器 4k 可以设置过期时间 */
 
-     document.cookie = "name = 'xiaoming'"
 
-     var date = new Date()
 
-     date.setDate(date.getDate() + 1)
 
-     console.log(date.toUTCString())
 
-     document.cookie = "password = '123';expires= " + date.toUTCString()
 
-     function setCookie(key, value, expires) {
 
-       var date = new Date()
 
-       date.setDate(date.getDate() + expires)
 
-       document.cookie = key + '=' + value + ';expires=' + date.toUTCString()
 
-     }
 
-     setCookie('address', 'harbin', 4)
 
-     function getCookie(key) {
 
-       var cookie = document.cookie
 
-       console.log(cookie.split(';'))
 
-       /* 
 
-       .split 方法 去拆分字符串
 
-       */
 
-       var arr = cookie.split(';')
 
-       console.log(arr)
 
-       for (var i = 0; i < arr.length; i++) {
 
-         var tmp = arr[i].split('=')
 
-         console.log(tmp)
 
-         /* trim() */
 
-         if (tmp[0].trim() == key) {
 
-           return tmp[1]
 
-         }
 
-       }
 
-     }
 
-     getCookie()
 
-     console.log(getCookie('address'))
 
-     function delCookie(key) {
 
-       var date = new Date()
 
-       date.setDate(date.getDate() - 1)
 
-       document.cookie = key + '=null;expires=' + date.toUTCString()
 
-     }
 
-     delCookie('password')
 
-   </script>
 
- </body>
 
- </html>
 
 
  |