l
获取系统时间
l Date对象
l getHours、getMinutes、getSeconds
l显示系统时间
l 字符串连接
l 空位补零
l设置图片路径
l charAt方法
<!DOCTYPE HTML>
<html><head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
function toDou(n)
{
if(n<10)
{
return '0'+n;
}
else
{
return ''+n;
}
}
window.οnlοad=function ()
{
var aImg=document.getElementsByTagName('img');
function tick(){
var oDate=new Date();
var str=toDou(oDate.getHours())+toDou(oDate.getMinutes())+toDou(oDate.getSeconds());
for(var i=0;i<aImg.length;i++)
{
aImg[i].src='img/'+str.charAt(i)+'.png';
}
}
setInterval(tick, 1000);
tick();
};
</script>
</head>
<body style="background:black; color: white; font-size:50px;">
<img src="img/0.png" />
<img src="img/0.png" />
:
<img src="img/0.png" />
<img src="img/0.png" />
:
<img src="img/0.png" />
<img src="img/0.png" />
</body>
</html>