js动态时钟 js实现动态时钟
林西相心 人气:0<!DOCTYPE html> <html> <head> <title>时钟</title> </head> <script type="text/javascript"> function todou(n){ if(n<10){ return '0'+n; } else { return ''+n; } } window.onload=function(){ setInterval(function(){ var date = new Date(); var ma = document.getElementsByTagName('img'); var str =todou(date.getHours())+todou(date.getMinutes())+todou(date.getSeconds()); for(var i=0;i<ma.length;i++){ ma[i].src='images/'+str[i]+'.png'; } // alert(todou(date.getSeconds())); // var date = new Date(); //alert(todou(date.getSeconds())); } ,1000) } </script> <body> <div style="background: grey;color: red; text-align: center;font-size: 100px;" > <img src="images/0.png" width="100px" height="90px"> <img src="images/0.png" width="100px" height="90px"> 时 <img src="images/0.png" width="100px" height="90px"> <img src="images/0.png" width="100px" height="90px"> 分 <img src="images/0.png" width="100px" height="90px"> <img src="images/0.png" width="100px" height="90px"> 秒 </div> </body> </html>
示例展示:
更多JavaScript时钟特效点击查看:JavaScript时钟特效专题
加载全部内容