onload 和 onunload

  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5. var i=1
  6. function starttimer()
  7. {
  8. document.getElementById('h_one').style.position="relative"
  9. document.getElementById('h_one').style.left=+i
  10. document.getElementById('h_two').style.position="relative"
  11. document.getElementById('h_two').style.top=+i
  12. i++
  13. timer=setTimeout("starttimer()",10)
  14. }
  15.  
  16. function stoptimer()
  17. {
  18. clearTimeout(timer)
  19. }
  20. </script>
  21.  
  22. </head>
  23. <body onload="starttimer()" onunload="stoptimer()">
  24.  
  25. <h1 id="h_one">标题一</h1>
  26. <h1 id="h_two">标题二</h1>
  27.  
  28. </body>
  29. </html>