-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.html
More file actions
73 lines (66 loc) · 1.7 KB
/
1.html
File metadata and controls
73 lines (66 loc) · 1.7 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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>控制div属性</title>
<style type="text/css">
* {
padding: 0;
margin: auto;
}
main {
margin: 10% auto;
}
main div {
width: 600px;
margin: 0 auto;
padding: 0;
text-align: center;
background-color: transparent;
}
main div button {
width: 80px;
height: 40px;
margin: auto 2%;
}
main .div {
width: 100px;
height: 100px;
margin: 5% auto;
padding: 0;
background-color: #2a6496;
}
</style>
</head>
<body>
<main>
<div class="btn-group">
<button>变宽</button>
<button>变高</button>
<button>变色</button>
<button>隐藏</button>
<button>重置</button>
</div>
<div class="div" id="div">
</div>
</main>
<script>
var changeStyle = function (ele, attr, value) {
ele.style[attr] = value;
}
window.onload = function(){
var oBtnGroup = document.getElementsByTagName('button');
var oDiv = document.getElementById('div');
var oAttr = ['width','height','background-color','display','display'];
var oValue = ['200px','200px','#f00','none','block']
for(var i=0;i<oBtnGroup.length;i++){
oBtnGroup[i].index= i
oBtnGroup[i].onclick = function(){
this.index == (oBtnGroup.length - 1) && (oDiv.style.cssText = '');
changeStyle(oDiv,oAttr[this.index],oValue[this.index]);
}
}
}
</script>
</body>
</html>