时间:2021-07-01 10:21:17 帮助过:29人阅读
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" type="text/css" href="系统CSS初始化.css"> <style> ul{ height: 100px; width: 600px; margin: 200px auto; } img{ float:left; } span{ font-size: 100px; float: left; display: block; position: relative; bottom: 20px; } </style> <script> window.onload=function () { function setDoub(n) { if(n<10) { n='0'+n; } else { n=''+n; } return n; } var aImg=document.getElementsByTagName("img"); function tick() { var date=new Date(); var str=setDoub(date.getHours())+setDoub(date.getMinutes())+setDoub(date.getSeconds()); for(var i=0;i<aImg.length;i++) { aImg[i].src="images/"+str[i]+".png"; } } tick(); setInterval(tick,1000) } </script> </head> <body> <ul id="ul1"> <img src="images/0.png"> <img src="images/0.png"> <span>:</span> <img src="images/0.png"> <img src="images/0.png"> <span>:</span> <img src="images/0.png"> <img src="images/0.png"> </ul> </body> </html>
以上就是用JS做时钟的详细内容,更多请关注Gxl网其它相关文章!