如何用JavaScript编写一个动态显示的时钟程序?

更新于
2026-09-26 18:40:15
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计296个文字,预计阅读时间需要2分钟。

如何用JavaScript编写一个动态显示的时钟程序?

原文示例:时钟

改写后:动态时钟

如何用JavaScript编写一个动态显示的时钟程序?

本文实例为大家分享了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 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时钟特效专题

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

本文共计296个文字,预计阅读时间需要2分钟。

如何用JavaScript编写一个动态显示的时钟程序?

原文示例:时钟

改写后:动态时钟

如何用JavaScript编写一个动态显示的时钟程序?

本文实例为大家分享了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 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时钟特效专题

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。