JavaScript中的setInterval的使用 发表于 2018-02-06 | 分类于 JavaScript 今天即兴的学了一会JavaScript的先关东西setinterval(定时器的使用)经常会用到图片的无缝滚动。。。下面是一个时间的设置 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152<html><head> <title></title> <meta charset="utf-8"></head><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='img/'+str[i]+'.png'; } }; setInterval(tick,1000); tick();};</script><body style="background:black;color:white;font-size:50px;"> <img src="img/0.png"/> <img src="img/0.png"/> : <img src="img/0.png"/> <img src="img/0.png"/> : <img src="img/0.png"/> <img src="img/0.png"/></body></html>