1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>流浪者</title>
6 <style>
7 #box{
8 width: 100px;
9 height: 100px;
10 background-color: green;
11 cursor: pointer;
12 }
13 </style>
14 </head>
15 <body>
16
17 <div id="box"></div>
18
19 <script>
20 var oDiv = document.getElementById('box');
21 oDiv.onclick = function () {
22 oDiv.style.width = '200px';
23 oDiv.style.height = '2oopx';
24 oDiv.style.backgroundColor = 'red';
25 }
26 </script>
27
28 </body>
29 </html>
<script type="text/java script">
window.onload = function () {
console.log("小马哥"); //等页面加载完毕时,打印字符串
}
</script>
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Document</title>
6 <style type="text/css">
7 *{
8 padding: 0;
9 margin: 0;
10 }
11 .top-banner{
12 /*position: relative;*/
13 background-color: rgb(230, 15, 82);
14 }
15 .top-banner .w{
16 width: 1190px;
17 position: relative;
18 margin: 0 auto;
19 }
20 .top-banner .banner{
21 display: block;
22 width: 100%;
23 height: 80px;
24 background: url('./close.jpg') no-repeat center 0;
25 }
26 .top-banner .close{
27 position: absolute;
28 right: 0;
29 top:0;
30 text-decoration: none;
31 color: white;
32 width: 20px;
33 height: 20px;
34 line-height: 20px;
35 text-align: center;
36 }
37 .hide{
38 display: none;
39 }
40
41 </style>
42 </head>
43 <body>
44 <div class="top-banner" id="topBanner">
45 <div class="w">
46 <a href="#" class="banner"></a>
47 <a href="#" class="close" id="closeBanner">x</a>
48 </div>
49 </div>
50 <script type="text/java script">
51 // /需求:点击案例,隐藏盒子。
52 //思路:点击a链接,让top-banner这个盒子隐藏起来(加隐藏类名)。
53
54 window.onload = function(){
55 // /1.获取事件源和相关元素
56 var closeBanner = document.getElementById('closeBanner'