首页 > 代码库 > javascript-定时器

javascript-定时器

一、时钟:

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
 <style>
  #div1 {background: black;color: white;font-size: 50}
 </style>
 <script>


  window.onload=function(){   

   var od=document.getElementById(‘div1‘)
   var ai=od.getElementsByTagName(‘img‘)

   function tick(){
    
    var data1=new Date()
    var str1=toDou(data1.getHours())+toDou(data1.getMinutes())+toDou(data1.getSeconds())
    for(var i=0;i<ai.length;i++){
     ai[i].src=http://www.mamicode.com/‘img/‘+str1[i]+‘.png‘
    }

   }


   setInterval(tick,1000)
   tick()
  }


  function toDou(n){
   if (n<10){
    return ‘0‘+n
   }else{
    return ‘‘+n
   }
  }


 </script>
</head>
<body>
 <div id="div1">
  <img src="http://www.mamicode.com/img/1.png" >
  <img src="http://www.mamicode.com/img/2.png" >:
  <img src="http://www.mamicode.com/img/3.png" >
  <img src="http://www.mamicode.com/img/4.png" >:
  <img src="http://www.mamicode.com/img/5.png" >
  <img src="http://www.mamicode.com/img/6.png" >
 </div>
</body>
</html>




javascript-定时器