-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson1.1.html
More file actions
50 lines (45 loc) · 1.01 KB
/
lesson1.1.html
File metadata and controls
50 lines (45 loc) · 1.01 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#square {
height: 100px;
width: 100px;
margin: 10px auto 0 auto;
background-color: greenyellow;
}
#control {
text-align: center;
}
</style>
</head>
<body>
<div id="control">
<button>变宽</button>
<button>变高</button>
<button>变色</button>
<button>隐藏</button>
<button>显示</button>
</div>
<div id="square"></div>
</body>
<script>
var changeStyle=function(elem,arr,value){
elem.style[arr]=value;
};
var oBtn=document.getElementById("control").getElementsByTagName("button");
var oDiv=document.getElementById("square");
var oArr=["width","height","background","display","display"];
var oVal=["200px","200px","red","none","block"];
window.onload=function(){
for(var i=0;i<=oBtn.length;i++){
oBtn[i].index=i;//此处有疑问
oBtn[i].onclick=function(){
changeStyle(oDiv,oArr[this.index],oVal[this.index]);
}
}
};
</script>
</html>