1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title></title>
6 <style type="text/css">
7 #box{
8 width: 200px;
9 height: 500px;
10 background: gray;
11 }
12 .child{
13 width: 100%;
14 height: 100px;
15 background: red;
16 border: 1px solid black;
17 }
18 </style>
19 </head>
20 <body>
21 <div id="box">
22 <div class="child"></div>
23 <div class="child"></div>
24 <div class="child"></div>
25 </div>
26 </body>
27
28 <script type="text/javascript">
29 var box = document.getElementById("box");
30 box.onclick = function(){
31 this.style.background= "green";
32 }
33
34
35
36
37 function fun1{
38
39 }console.log(this);// this 代指 window
40
41
42
43
44 // 补充知识点:
45 var value = document.getElementsByTagName("div");
46 var fatherBox = document.getElementById("box");
47 // 获取 box 下面所有的 div 块
48 var childs = fatherBox.getElementsByTagName("div");
49
50 </script>
51
52 </html>