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