-
Notifications
You must be signed in to change notification settings - Fork 0
/
选项卡1.html
93 lines (83 loc) · 1.91 KB
/
选项卡1.html
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>选项卡</title>
<style>
* {
margin: 0;
padding: 0;
}
ul, ol {
list-style: none;
}
a {
text-decoration: none;
}
#container {
width: 400px;
height: 300px;
margin: 100px auto;
}
#tab {
overflow: hidden;
}
#tab li {
width: 120px;
height: 30px;
background: #999;
float: left;
margin-right: 5px;
text-align: center;
line-height: 30px;
cursor: pointer;
}
#tab .selected {
background: #000000;
color: #ffffff;
}
#content {
height: 270px;
background: #cccccc;
border-top: 1px solid #000;
}
#content div {
display: none;
}
#content .selected {
display: block;
}
</style>
</head>
<body>
<div id="container">
<ul id="tab">
<li class="selected">html</li>
<li>css</li>
<li>javascript</li>
</ul>
<div id="content">
<div class="selected">001</div>
<div>002</div>
<div>003</div>
</div>
</div>
<script>
var oTab = document.getElementById("tab");
var oContent = document.getElementById("content");
var aLi = oTab.getElementsByTagName("li");
var aDiv = oContent.getElementsByTagName("div");
for(var i=0;i<aLi.length;i++){
aLi[i].index = i;
aLi[i].onclick = function(){
for(var i=0;i<aLi.length;i++){
aLi[i].className = "";
aDiv[i].className = "";
}
this.className = "selected";
aDiv[this.index].className = "selected";
}
}
</script>
</body>
</html>