<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数码时钟</title>
<script type="text/javascript">
/*数字不满足两位的前面加个0*/
function toDou(n){
if(n<10){
return '0'+n;
}else{
return ''+n;
}
}
/*str[i] 就等于 str.charAt(i) 兼容性问题*/
window.onload = 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: #000; color: white;font-size:100px;">
<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>