정보 보관 ver1.0

window.setTimeout() & window.clearTimeout()을 이용한 타이머

James Wetzel 2010. 11. 25. 15:19

<!doctype html>
<html>
 <head>
  <script type="text/javascript" language="javascript">
   var timerObj;
   var times = 0;

   window.attachEvent("onload", timerStart());

   function timerStart()
   {    
    timerObj = window.setTimeout("timer()", 1000*10)
   }

   function timer()
   {
    times = times + 10;
    window.document.getElementById("content").innerText = times+"초가 지났습니다.";

    clearTimeout("timerObj");
    setTimeout("timer()", 1000*10)
   }
  </script>
 </head>
 <body>
  <div id="content">10초 후 내용이 출력됩니다.</div>
 </body>
</html>

728x90
반응형