zsydgithub hai 1 ano
pai
achega
69c5eca7cb
Modificáronse 3 ficheiros con 138 adicións e 0 borrados
  1. 66 0
      Html5/10_本地存储.html
  2. 30 0
      Html5/11_本地存储2.html
  3. 42 0
      Html5/9_深拷贝2.html

+ 66 - 0
Html5/10_本地存储.html

@@ -0,0 +1,66 @@
+<!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='zs'"
+
+    var date = new Date()
+    date.setDate(date.getDate() + 1)
+    console.log(date)
+    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)
+
+      /* 
+        创建一个arr数组
+        .split方法 把字符串拆分成数组
+        ["name='zs'", " password='123'", ' address=harbin']
+      */
+      var arr = cookie.split(';')
+      console.log(arr)
+      for (var i = 0; i < arr.length; i++) {
+        console.log(arr[i])
+        var tmp = arr[i].split('=')
+        console.log(tmp)
+        /* trim() */
+        if (tmp[0].trim() == key) {
+          return tmp[1]
+        }
+      }
+    }
+    console.log(getCookie('name'))
+
+
+    function delCookie(key) {
+      var date = new Date()
+      date.setDate(date.getDate() - 1)
+      document.cookie = key + '=null;expires=' + date.toUTCString()
+    }
+    delCookie('password')
+  </script>
+</body>
+
+</html>

+ 30 - 0
Html5/11_本地存储2.html

@@ -0,0 +1,30 @@
+<!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>
+    /* localStorage 大小 5M  一直存储  */
+    // localStorage.isNow = true
+
+    // console.log(localStorage.isNow)
+
+    /* sessionStorage 大小 5M  会话窗口关闭失效 */
+    // sessionStorage.age = 18
+
+    /* 
+      共同点:都是保存在浏览器里面的
+      区别:
+
+      cookie 大小4K  可以设置过期时间
+      localstorage  大小5M 除非手动删除 否则一直存在
+      sessionstorage 大小5M 窗口关闭失效
+      
+    */
+  </script>
+</body>
+</html>

+ 42 - 0
Html5/9_深拷贝2.html

@@ -0,0 +1,42 @@
+<!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>
+    function deepClone(data) {
+      var tmp = {}
+      if (typeof data == 'object') {
+        // if(Array.isArray(data)){
+        //   tmp = []
+        // } else {
+        //   tmp = {}
+        // }
+        tmp = Array.isArray(data) ? [] : {}
+        for(key in data){
+          if(typeof data == 'object'){
+            tmp[key] == deepClone(data[key])
+          } else {
+            tmp[key] = data[key]
+          }
+        }
+      } else {
+        tmp = data
+      }
+    }
+
+    // var arr1 = [1,2,3]
+    // var person = {
+    //   name:'zs'
+    // }
+    // console.log(Array.isArray(person))
+  </script>
+</body>
+
+</html>