js實現動態時鐘
本文實例為大家分享了js實現動態時鐘的具體代碼,供大家參考,具體內容如下
<!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 > <img src='http://www.aoyou183.cn/bcjs/images/0.png' height='90px'> <img src='http://www.aoyou183.cn/bcjs/images/0.png' height='90px'> 時 <img src='http://www.aoyou183.cn/bcjs/images/0.png' height='90px'> <img src='http://www.aoyou183.cn/bcjs/images/0.png' height='90px'> 分 <img src='http://www.aoyou183.cn/bcjs/images/0.png' height='90px'> <img src='http://www.aoyou183.cn/bcjs/images/0.png' height='90px'> 秒</div></body></html>
示例展示:
更多JavaScript時鐘特效點擊查看:JavaScript時鐘特效專題
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章: