<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <script src="js/myJs_file.js"></script> <script> var aImg = document.getElementsByTagName("img"); function showTime(){ var myTime = new Date(); var iHours = myTime.getHours(); var iMinutes = myTime.getMinutes(); var iSeconds = myTime.getSeconds(); var str = addZero(iHours)+addZero(iMinutes)+addZero(iSeconds); for(var i=0;i<str.length;i++){ aImg[i].src = "img/" + str.charAt(i) + ".JPG"; } } setInterval(showTime, 1000); showTime(); </script> </body> </html> ps: myJs_file.js里面其实就是一个利用三目运算符判断数字是否大于10,当大于10时,输出;小于10,则给该数字前面加0;
时间: 2024-10-16 08:48:09