Day3-----clock

//------------------------通过获取系统时间,添加定时器和添0操作完成日期和时间的显示

<html>
<head><title>clock</title></head>
<style type="text/css">
body{font-size: 25px;vertical-align: top;}
</style>
<script type="text/javascript">
function addZero(str){
if(str<10) return '0'+str;
else return str;
}
function updateTime(){
var date=new Date();
oImg=document.getElementsByTagName('img');
var str=''+date.getFullYear()+addZero((date.getMonth()+1))+addZero(date.getDate())+date.getDay()+addZero(date.getHours())+addZero(date.getMinutes())+addZero(date.getSeconds());
for(i=0;i<oImg.length;i++){
oImg[i].src="pic/"+str[i]+".png";
}
}
window.onload=function(){
updateTime();
setInterval(updateTime,1000);
}
</script>
<body>
<img><img><img><img>/
<img><img>/
<img><img>
The <img>th
<br/>
<img><img>:
<img><img>:
<img><img>
</body>
</html>

原文地址:https://www.cnblogs.com/fleshy/p/4114978.html