首页 > 代码库 > js时钟
js时钟
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style type="text/css"> 7 *{ 8 margin:0; 9 padding:0; 10 } 11 h2{ 12 width:50px; 13 margin:0 auto; 14 } 15 div{ 16 width: 300px; 17 text-align: center; 18 background: red; 19 margin:50px auto; 20 } 21 </style> 22 <script type="text/javascript"> 23 window.onload= function () { 24 getTime(); 25 setInterval(getTime,1000); 26 function getTime() { 27 var date = new Date(); 28 var hours = date.getHours(); 29 var one = parseInt(hours / 10); 30 var two = parseInt(hours % 10); 31 var minutes = date.getMinutes(); 32 var three = parseInt(minutes / 10); 33 var four = parseInt(minutes % 10); 34 var second = date.getSeconds(); 35 var five = parseInt(second / 10); 36 var six = parseInt(second % 10); 37 var imgs = document.getElementsByTagName("img"); 38 imgs[0].src = "images/" + one + ".png"; 39 imgs[1].src = "images/" + two + ".png"; 40 imgs[2].src = "images/" + three + ".png"; 41 imgs[3].src = "images/" + four + ".png"; 42 imgs[4].src = "images/" + five + ".png"; 43 imgs[5].src = "images/" + six + ".png"; 44 } 45 } 46 </script> 47 </head> 48 <body> 49 <h2>时钟</h2> 50 <div> 51 <img src="images/0.png"> 52 <img src="images/0.png">: 53 <img src="images/0.png"> 54 <img src="images/0.png">: 55 <img src="images/0.png"> 56 <img src="images/0.png"> 57 </div> 58 </body> 59 </html>
js时钟
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。