zsydgithub 2 years ago
parent
commit
89a5cfdc87

+ 62 - 0
7_Html5/10_本地存储.html

@@ -0,0 +1,62 @@
+<!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  默认的有效期 为当前对话窗口  
+    可以通过 expires 设置过期时间
+    */
+    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('age',18,2)
+
+
+    function getCookie(key){
+      var cookie = document.cookie
+      console.log(cookie)
+      /* 创建一个arr 存放字符串分开 
+      .split() 把字符串 拆分成数组
+      ["password='123'", " name='zs'", ' age=18']
+      */
+      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]
+        }
+      }
+    }
+    console.log(getCookie('age'))
+
+
+    function delCookie(key){
+      var date = new Date()
+      date.setDate(date.getDate()-1)
+      document.cookie = key+ '=null;expires='+ date.toUTCString()
+    }
+    delCookie('age')
+  </script>
+</body>
+</html>

+ 22 - 0
7_Html5/11_本地存储2.html

@@ -0,0 +1,22 @@
+<!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.isLogin = true
+  console.log(localStorage.isLogin)
+  /* 
+    sessionStorage 会话窗口关闭失效  本地存储 大小5M
+  */
+  sessionStorage.age = 18
+  </script>
+</body>
+</html>

+ 19 - 0
7_Html5/12_总结.html

@@ -0,0 +1,19 @@
+<!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>
+  <!-- 
+    HTML5 的新特性有哪些
+    新的语义化标签 例如<header><nav>
+    新增表单控件 比如数字 日期 滑块 时间
+    多媒体支持 video audio
+    本地存储
+    新的属性获取方法
+  -->
+</body>
+</html>

+ 1 - 1
7_Html5/8_深拷贝.html

@@ -30,7 +30,7 @@
 
       var person = {
         name:'zs',
-        zge:18,
+        age:18,
         school:{
           address:'harbin',
           num: 10000

+ 39 - 0
7_Html5/9_深克隆2.html

@@ -0,0 +1,39 @@
+<!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(Array.isArray(data)){
+      //   tmp = []
+      // } else {
+      //   tmp = {}
+      // }
+      if(typeof data == 'object'){
+        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
+      }
+      return tmp
+    }
+    var a = ['lisi',18]
+    var b = deepClone(a)
+    b[0] = 'zs'
+    console.log(b)
+    console.log(a)
+  </script>
+</body>
+</html>