html code to realize a simple digital clock

Main code: You can send me a png picture by private message, and Aoli will give it! ! !

<!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>无标题文档</title>
<script>
function toDouble(n){
     
     
	
	if(n<10){
     
     
		return '0'+n;
		}
		else{
     
     
			return ''+n;
			}
	}
window.onload=function()
 {
     
     
	  var aImg=document.getElementsByTagName('img');
	  function tick(){
     
     
		  
	  var oDate=new Date();  //时间对象
	  var str=toDouble(oDate.getHours())+toDouble(oDate.getMinutes())+toDouble(oDate.getSeconds());
	  for(var i=0;i<aImg.length;i++)
	  {
     
     
		  aImg[i].src='img/'+str[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>

Effect picture:
Insert picture description here

Guess you like

Origin blog.csdn.net/a_liang123/article/details/115016511