JS定时器的使用--数码时钟

it2022-05-05  124

<title>无标题文档</title> <script> function toDou(n){ if(n<10){ return '0'+n; }else{ return ''+n; //保证返回的都是字符串,避免放在一起成了相加 } } window.onload=function (){ var aImg=document.getElementsByTagName('img'); function tick(){ var oDate=new Date(); var str=toDou(oDate.getHours())+toDou(oDate.getMinutes())+toDou(oDate.getSeconds()); for(var i=0;i<aImg.length;i++){ aImg[i].src='images/'+str.charAt(i)+'.gif'; } } setInterval(tick,1000); tick(); }; </script> </head> <body style="background:#999; color:white;"> <img src="images/0.gif"> <img src="images/0.gif"> : <img src="images/0.gif"> <img src="images/0.gif"> : <img src="images/0.gif"> <img src="images/0.gif"> </body>

 

小问题:var str='abcdef';alert(str[0]); 在IE7下显示undefined用str.charAt(0)可以解决这个兼容性问题

数码时钟获取系统时间Date对象getHours、getMinutes、getSecondsDate对象其他方法年 getFullYear()月 getMonth() 从0开始日 getDate()星期 getDay() 0,1,2,3,4,5,6 0代表周末

转载于:https://www.cnblogs.com/919czzl/p/4314074.html

相关资源:各显卡算力对照表!

最新回复(0)