10
0
fengchuanyu 8 сар өмнө
parent
commit
66f048f29c

+ 23 - 0
7_HTML5/10_dataset.html

@@ -0,0 +1,23 @@
+<!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>
+    <ul>
+        <li data-hash="fistr" data-aa="hello">first page</li>
+        <li data-hash="second">second page</li>
+        <li data-hash="third">third page</li>
+    </ul>
+    <script>
+        let aLi = document.querySelectorAll("li");
+        for(let i =0;i<aLi.length;i++){
+            aLi[i].onclick = function(e){
+                console.log(e.target.dataset.hash);
+            }
+        }
+    </script>
+</body>
+</html>

+ 65 - 0
7_HTML5/练习题3_历史管理.html

@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        ul{
+            margin: 0;
+            padding: 0;
+            display: flex;
+        }
+        li{
+            list-style: none;
+            width: 100px;
+            height: 50px;
+            background-color: #aaa;
+            text-align: center;
+            line-height: 50px;
+            font-weight: bold;
+            color: #fff;
+        }
+        .active{
+            background-color: #000;
+        }
+    </style>
+</head>
+<body>
+    <ul>
+        <li class="active">fist</li>
+        <li>second</li>
+        <li>third</li>
+    </ul>
+    <script>
+        let aLi = document.querySelectorAll("li");
+        let arr = ['first','second','third'];
+        for(let i = 0;i<aLi.length;i++){
+            // aLi[i].index = i;
+            aLi[i].onclick = function(){
+                for(let j=0;j<aLi.length;j++){
+                    aLi[j].className = "";
+                }
+                this.className = "active";
+                // console.log(i);
+                location.hash = arr[i];
+                // console.log(arr[this.index]);
+                // location.hash = arr[this.index]
+            }
+        }
+
+        window.onhashchange = function(){
+            // console.log(location.hash)
+            let thisHas = location.hash.substr(1);
+            // console.log(thisHas);
+            // console.log(arr.indexOf(thisHas));
+            let thisIndex =  arr.indexOf(thisHas)
+            for(let i =0;i<aLi.length;i++){
+                aLi[i].className = "";
+            }
+            aLi[thisIndex].className = "active";
+
+        }
+    </script>
+</body>
+</html>

+ 0 - 0
8_移动端/1_viewport.html