-
Notifications
You must be signed in to change notification settings - Fork 6
/
046-面向对象选项卡.html
131 lines (129 loc) · 2.31 KB
/
046-面向对象选项卡.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
list-style-type: none;
text-decoration: none;
}
#tab {
width: 304px;
height: 300px;
margin: 30px auto;
}
#tab ul {
display: block;
height: 30px;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
}
#tab ul li {
float: left;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
border-right: 1px solid #ccc;
}
#tab .tab_cont {
border: 1px solid #ccc;
height: 300px;
}
#tab2 {
width: 304px;
height: 300px;
margin: 30px auto;
}
#tab2 ul {
display: block;
height: 30px;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
}
#tab2 ul li {
float: left;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
border-right: 1px solid #ccc;
}
#tab2 .tab_cont {
border: 1px solid #ccc;
height: 300px;
}
.active {
background: red;
}
</style>
<script>
window.onload = function()
{
new TablSwitch("tab");
new TablSwitch("tab2");
}
function TablSwitch(id)
{
var oTab = document.getElementById(id);
this.aBtn = oTab.getElementsByTagName("li");
this.aDiv = oTab.getElementsByTagName("div");
var _this = this;
for(var i = 0; i < this.aBtn.length; i++)
{
this.aBtn[i].index = i;
this.aBtn[i].onclick = function()
{
_this.tab(this);
}
}
}
TablSwitch.prototype.tab = function(oBtn)
{
for(var i = 0; i < this.aBtn.length; i++)
{
this.aBtn[i].className = "";
this.aDiv[i].style.display = "none";
}
oBtn.className = "active";
this.aDiv[oBtn.index].style.display = "block";
}
</script></head>
<body>
<div id="tab">
<ul id="ul1">
<li class="active">
<a href="#">选项一</a>
</li>
<li>
<a href="#">选项一</a>
</li>
<li>
<a href="#">选项一</a>
</li>
</ul>
<div class="tab_cont">选项1内容</div>
<div class="tab_cont" style="display:none;">选项2内容</div>
<div class="tab_cont" style="display:none;">选项3内容</div>
</div>
<div id="tab2">
<ul id="ul1">
<li class="active">
<a href="#">选项一</a>
</li>
<li>
<a href="#">选项一</a>
</li>
<li>
<a href="#">选项一</a>
</li>
</ul>
<div class="tab_cont">选项1内容</div>
<div class="tab_cont" style="display:none;">选项2内容</div>
<div class="tab_cont" style="display:none;">选项3内容</div>
</div>
</body>
</html>