JavaScript实现数字时钟功能
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <center> <body style="background: #4A4848;font-size: 30px;padding-top: 50px;"> <img src="images/0.png" /> <img src="images/0.png" /> : <img src="images/0.png" /> <img src="images/0.png" /> : <img src="images/0.png" /> <img src="images/0.png" /> <script> function bijiao(n) { if(n<10) { return '0'+n; } else { return ''+n; } } function tick() { var aimg=document.getElementsByTagName('img'); var odata= new Date(); var str=bijiao(odata.getHours())+bijiao(odata.getMinutes())+bijiao(odata.getSeconds()); for(var i=0;i<aimg.length;i++) { aimg[i].src='images/'+str.charAt(i)+'.png'; } } setInterval(tick,1000); tick(); </script> </body> </center> </html>
欢迎访问每天进步网:https://meitianjinbu.cn/