首页 > 代码库 > DHTML_____window对象的事件

DHTML_____window对象的事件

技术分享
<html>
<head>
  <meta charset="utf-8">
  <title>window对象事件</title>
</head>

<body onload="alert(‘欢迎‘)" onunload="alert(‘再见‘)" onbeforeunload="window.event.returnValue=http://www.mamicode.com/‘请小心行事!‘">
 <!--onbeforeunload 包括刷新和关闭窗口-->
<div id="scrollDiv"></div>

<input type="button" onclick="clearInt()" value="Cancel"/>

<script language="javascript">
//01 onl oad
//02 onunload
//03 onbeforeunload
var set=setInterval("demo()",2000);

var str="";
function demo(){
    var div=document.getElementById("scrollDiv");
    str+="欢迎光临<br/>";
    div.innerHTML=str;
}
function clearInt(){
    window.clearInterval(set);
}
//05 onclick

//06 onm ouseover onm ouseout  onm ousemove 

//07 onm ousedown onm ouseup

//08 onkeydown onkeyup onkeypress

</script>
</body>
</html>
View Code
 1 <html>
 2 <head>
 3   <meta charset="utf-8">
 4   <title>window对象事件</title>
 5 </head>
 6 
 7 <body onload="alert(‘欢迎‘)" onunload="alert(‘再见‘)" onbeforeunload="window.event.returnValue=http://www.mamicode.com/‘请小心行事!‘">
 8  <!--onbeforeunload 包括刷新和关闭窗口-->
 9 <div id="scrollDiv"></div>
10 
11 <input type="button" onclick="clearInt()" value="Cancel"/>
12 
13 <script language="javascript">
14 //01 onl oad
15 //02 onunload
16 //03 onbeforeunload
17 var set=setInterval("demo()",2000);
18 
19 var str="";
20 function demo(){
21     var div=document.getElementById("scrollDiv");
22     str+="欢迎光临<br/>";
23     div.innerHTML=str;
24 }
25 function clearInt(){
26     window.clearInterval(set);
27 }
28 //05 onclick
29 
30 //06 onm ouseover onm ouseout  onm ousemove 
31 
32 //07 onm ousedown onm ouseup
33 
34 //08 onkeydown onkeyup onkeypress
35 
36 </script>
37 </body>
38 </html>

 

DHTML_____window对象的事件