初探js特效魅力之定時器的使用one

初探js特效魅力之簡易時鐘的使用one

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js特效</title>
<!-- <link id="link1" rel="stylesheet" type="text/css" href="css1.css" />-->
<script>
 
 window.οnlοad=function(){
  function toD(n){
   if(n<10){
    return '0'+n; 
   }
   else{
    return ''+n; 
   }
  }
  var oImg=document.getElementsByTagName("img");
  function tick(){
    var oDate=new Date();
    var str=toD(oDate.getHours())+toD(oDate.getMinutes())+toD(oDate.getSeconds()); 
    for(var i=0;i<str.length;i++){
     oImg[i].src=str.charAt(i)+".jpg";     
    } 
  }
  setInterval(tick,1000);
  tick();
 }
</script>
<style>
img{
 width:50px;
 height:70px;
}
label{
 font-size:70px;
}
</style>
</head>
<body>
 <img src="0.jpg" />
    <img src="0.jpg" />
    <label>:</label>
    <img src="0.jpg" />
    <img src="0.jpg" />
    <label>:</label>
    <img src="0.jpg" />
    <img src="0.jpg" />
</body>
</html>

發佈了63 篇原創文章 · 獲贊 28 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章