asimryu

simple timer example 1

Jun 15th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.60 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <script src="http://code.jquery.com/jquery-latest.js"></script>
  6. </head>
  7. <body>
  8. <h1 id="clock">My First JavaScript</h1>
  9. <button id="start">시작</button>
  10. <button id="stop">중지</button>
  11. <script>
  12.     var timer = null;
  13.     $(function(){
  14.  
  15.         $("#start").click(function(){
  16.             if( timer == null ) {
  17.                 timer = setInterval(function(){
  18.                     $("#clock").html(Date());
  19.                 },1000);
  20.             }
  21.         });
  22.  
  23.         $("#stop").click(function(){
  24.             if( timer != null ) {
  25.                 clearInterval(timer);
  26.                 timer = null;
  27.             }
  28.         });
  29.  
  30.     });
  31.  
  32. </script>
  33. </body>
  34. </html>
Advertisement
Add Comment
Please, Sign In to add comment