setInterval()





js/script.js
  • function funClock() {
  •  var date = new Date();
  •  var hours = date.getHours();
  •  var minutes = date.getMinutes();
  •  var seconds = date.getSeconds();
  •  if(hours < 10) {
  •   hours = '0' + hours;
  •  }
  •  if(minutes < 10) {
  •   minutes = '0' + minutes;
  •  }
  •  if(seconds < 10) {
  •   seconds = '0' + seconds;
  •  }
  •  var time = hours + ':' + minutes + ':' + seconds;
  •  document.getElementById('t').innerHTML = time;
  • }
  •  
  • function funMake() {
  •  setInterval('funClock()', 1000);
  • }
  • function funClock() {
  •  var date = new Date();
  •  var hours = date.getHours();
  •  var minutes = date.getMinutes();
  •  var seconds = date.getSeconds();
  •  if(hours < 10) {
  •   hours = '0' + hours;
  •  }
  •  if(minutes < 10) {
  •   minutes = '0' + minutes;
  •  }
  •  if(seconds < 10) {
  •   seconds = '0' + seconds;
  •  }
  •  var time = hours + ':' + minutes + ':' + seconds;
  •  document.getElementById('t').innerHTML = time;
  • }
  •  
  • function funMake() {
  •  setInterval('funClock()', 1000);
  • }


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  •  <time id="t"></time>
  •  <script>
  •   funMake();
  •  </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  •  <time id="t"></time>
  •  <script>
  •   funMake();
  •  </script>
  • </body>
  • </html>