数码时钟

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    .div1{
      color:#fff;
      background: #171717;
      font-size:50px;
      text-align:center;
    }
  </style>
</head>
<script>
  function getDate(n){
    if(n<10){
      return '0'+n;
    }else{
      return ''+n;
    }
  }
window.onload=function(){
  var oImg=document.getElementsByTagName('img');
  function timer(){
    var oDate=new Date();
    var str=getDate(oDate.getHours())+getDate(oDate.getMinutes())+getDate(oDate.getSeconds());
    for(var i=0;i<oImg.length;i++){
      oImg[i].src='images/'+str[i]+'.png';
    }
  }
  setInterval(timer,1000);
  timer();
}
</script>
<body class="div1">
  <img src="images/0.png">
  <img src="images/0.png">
  :
  <img src="images/0.png">
  <img src="images/0.png">
  :
  <img src="images/0.png">
  <img src="images/0.png">

</body>
</html>

猜你喜欢

转载自blog.csdn.net/sunjynyue/article/details/78165019