1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <title>美女时钟</title> 6 <script type="text/javascript"> 7 onload = function () { 8 var mnClock = function () { 9 //在div里增加一个图片标签 10 var image = document.getElementById("img1"); 11 var image = document.getElementById("img2"); 12 var image = document.getElementById("img3"); 13 var image = document.getElementById("img4"); 14 var image = document.getElementById("img5"); 15 var image = document.getElementById("img6"); 16 //dv.appendChild(document.createElement("img")); 17 18 //获取当前时间,小时,分钟,如12:34 19 var myDate = new Date(); 20 var hour = myDate.getHours(); 21 if (hour < 10) { 22 hour = "0" + hour; 23 } 24 var minute = myDate.getMinutes(); 25 if (minute < 10) { 26 minute = "0" + minute; 27 } 28 var second = myDate.getSeconds(); 29 if (second < 10) { 30 second = "0" + second; 31 } 32 //查找与时间对应的图片,如12_34,注意01:02这种格式 33 //把图片放入div标签里 34 //img.src = "source/mm_全/" + hour + "_" + minute + ".jpg"; 35 var hour1 = hour.toString().charAt(0); 36 37 var hour2 = hour.toString().charAt(1); 38 var minute1 = minute.toString().charAt(0); 39 var minute2 = minute.toString().charAt(1); 40 var second1 = second.toString().charAt(0); 41 var second2 = second.toString().charAt(1); 42 img1.src = "source/js_电子时钟/countdown-" + hour1 + ".png"; 43 img2.src = "source/js_电子时钟/countdown-" + hour2 + ".png"; 44 img3.src = "source/js_电子时钟/countdown-" + minute1 + ".png"; 45 img4.src = "source/js_电子时钟/countdown-" + minute2 + ".png"; 46 img5.src = "source/js_电子时钟/countdown-" + second1 + ".png"; 47 img6.src = "source/js_电子时钟/countdown-" + second2 + ".png"; 48 } 49 setInterval(mnClock, 1000); 50 } 51 </script> 52 </head> 53 <body> 54 <div id = "dv"> 55 <img src="#" alt="Alternate Text" id = "img1"/> 56 <img src="#" alt="Alternate Text" id = "img2"/> 57 <img src="#" alt="Alternate Text" id = "img3"/> 58 <img src="#" alt="Alternate Text" id = "img4"/> 59 <img src="#" alt="Alternate Text" id = "img5"/> 60 <img src="#" alt="Alternate Text" id = "img6"/> 61 </div> 62 63 </body> 64 </html>
时间: 2024-10-14 09:35:50