bailing hai 1 semana
pai
achega
81ef78d2e4
Modificáronse 3 ficheiros con 99 adicións e 0 borrados
  1. BIN=BIN
      .DS_Store
  2. 49 0
      6.html5/10.本地存储.html
  3. 50 0
      6.html5/11.本地存储.html

BIN=BIN
.DS_Store


+ 49 - 0
6.html5/10.本地存储.html

@@ -0,0 +1,49 @@
+<!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>
+    
+    
+    <!-- 
+        WebStoarge 和 Cookie 
+        本地存储:localStorage:除非手动删除 否则不会消失
+        会话存储:SessionStorage:关闭页面就会消失
+    -->
+        <script>
+            // 设置
+            localStorage.setItem("name","Lucy")
+            localStorage.age = 18;
+            localStorage["sex"] = "女";
+
+            // 读取
+            console.log(localStorage.getItem("name"))
+            console.log(localStorage.age)
+            console.log(localStorage["sex"])
+
+            // 删除一条
+            // localStorage.removeItem("name")
+
+            // 删除全部
+            // localStorage.clear();
+
+            // 得到某个下表索引的key值
+            console.log(localStorage.key(0))
+
+            let list = [{
+                name:"aa",
+                id:1
+            },{
+                name:"bb",
+                id:2
+            },{
+                name:"cc",
+                id:3
+            }]
+            localStorage.setItem("newList",JSON.stringify(list))
+        </script>
+</body>
+</html>

+ 50 - 0
6.html5/11.本地存储.html

@@ -0,0 +1,50 @@
+<!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>
+    <script>
+        document.cookie = "name1 = LiLi";
+        var date = new Date();
+        date.setDate(date.getDate() + 7);
+        console.log(date.toUTCString())
+        console.log(date)
+        document.cookie = 'flower=丁香花;expires=' + date.toUTCString();
+        // 设置
+        function setCookie(name1, value1, day1) {
+            var date = new Date();
+            date.setDate(date.getDate() + day1);
+            document.cookie = name1 + '=' + value1 + ';expires=' + date.toUTCString();
+        }
+        setCookie('weather', '晴天', 3)
+        // 删除
+        function delCookie(name1) {
+            var date = new Date();
+            date.setDate(date.getDate() - 1);
+            document.cookie = name1 + '= null;expires=' + date.toUTCString();
+        }
+        delCookie("flower")
+        // 查询
+        function getCookie(name) {
+            var cookie = document.cookie;
+            console.log(cookie,'cccc')
+           var arr = cookie.split(";");
+            console.log(arr,'aaa')
+            for(var i=0;i<arr.length;i++) {
+                var item = arr[i].split("=");
+                console.log(item,'item')
+                if(item[0].trim() == name) {
+                    return item[1]
+                }
+            }
+        }
+        console.log(getCookie("weather"))
+    </script>
+</body>
+
+</html>