-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
96 lines (78 loc) · 2.32 KB
/
index.html
File metadata and controls
96 lines (78 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!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>
.box {
width: 300px;
height:200px;
border: 1px solid red;
margin:0 auto;
}
.title{
width: 100%;
height: 30px;
border: 1px solid #ccc;
}
.title a {
float: left;
display: inline-block;
width: 25%;
height: 100%;
line-height: 30px;
text-align: center;
background-color: #ccc;
}
.con{
width: 100%;
height: 170px;
overflow: hidden;
}
.conlist{
width: 100%;
height: 100%;
line-height: 30px;
border:1px solid brown;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<div class="title">
<a href="#">一</a>
<a href="#">二</a>
<a href="#">三</a>
<a href="#">四</a>
</div>
<div class="con">
<div class="conlist">11</div>
<div class="conlist">22</div>
<div class="conlist">33</div>
<div class="conlist">44</div>
</div>
</div>
<script>
//闭包
//link[i].index = i;
// (function (i) {
// link[i].onclick = function () {
// }
// }) (i)
var links = document.querySelectorAll(".title a")
var lists = document.querySelectorAll(".conlist")
for (let i = 0; i < links.length; i++) {
links[i].onclick = function () {
for (var j = 0; j < lists.length; j++) {
lists[j].style.display = "none";
links[j].style.background = "";
}
lists[i].style.display = "block";
links[i].style.background = "red";
}
}
</script>
</body>
</html>