-
Notifications
You must be signed in to change notification settings - Fork 0
/
面向对象-案例(选项卡).html
105 lines (94 loc) · 2.8 KB
/
面向对象-案例(选项卡).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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>面向对象-案例(选项卡)</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script type="text/javascript">
// 总共分了10份,准备给content 10份
setRem();
window.onresize = setRem;
function setRem() {
document.getElementsByTagName('html')[0].style.fontSize = document.documentElement.clientWidth / 10 + 'px';
}
</script>
<style>
.on {
background-color: brown;
color: beige;
}
.box div {
width: 5rem;
height: 5rem;
border: 1px solid #cccccc;
display: none;
font-size: 20px;
color: brown;
}
</style>
</head>
<body>
<div id="box" class="box">
<input type="button" value="click 1" class="on"/>
<input type="button" value="click 2"/>
<input type="button" value="click 3"/>
<div style="display: block">click 1</div>
<div>click 2</div>
<div>click 3</div>
</div>
<div id="box2" class="box">
<input type="button" value="click 1" class="on"/>
<input type="button" value="click 2"/>
<input type="button" value="click 3"/>
<div style="display: block">click 1</div>
<div>click 2</div>
<div>click 3</div>
</div>
<script>
class Tap {
constructor(id) {
this.oBox = document.getElementById(id);
this.aBtn = this.oBox.getElementsByTagName("input");
this.aDiv = this.oBox.getElementsByTagName("div");
this.iNow = 0;
this.init();
}
init() {
for (let i = 0; i < this.aBtn.length; i++) {
this.aBtn[i].onclick = function () {
this.iNow = i;
this.hide();
this.show(i);
document.title = this.iNow;
}.bind(this);
}
}
hide() {
for (let i = 0; i < this.aBtn.length; i++) {
this.aBtn[i].className = "";
this.aDiv[i].style.display = "none";
}
}
show(index) {
this.aBtn[index].className = "on";
this.aDiv[index].style.display = "block";
}
}
new Tap("box");
//继承
class AutoTap extends Tap {
next(){
this.iNow++;
if(this.iNow == this.aBtn.length)this.iNow=0;
this.hide();
this.show(this.iNow);
}
}
var at = new AutoTap("box2");
document.onclick= function(){
at.next();
}
</script>
</body>
</html>