效果展示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数码时钟</title>
<style>
body{
background: black;
color: white;
font-size: 40px;
}
img{
width: 40px;
}
</style>
<script>
function toDou(n){
if(n<10)
{
return '0'+n;
}
else
{
return ''+n;
}
}
window.onload=function () {
var aImg=document.getElementsByTagName('img');
//var str='192354';
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='../image视频and图片/数字'+str[i]+'.png';
}
}
tick();
setInterval(tick,1000); //每隔一秒刷新(执行)一次
};
</script>
</head>
<body>
<div>
<img src="../image视频and图片/数字0.png" alt="">
<img src="../image视频and图片/数字0.png" alt="">
:
<img src="../image视频and图片/数字0.png" alt="">
<img src="../image视频and图片/数字0.png" alt="">
:
<img src="../image视频and图片/数字0.png" alt="">
<img src="../image视频and图片/数字0.png" alt="">
</div>
</body>
</html>