数字时钟

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function getDigits()
  5. {
  6. num=new Array("/i/eg_0fdr.gif","/i/eg_1fdr.gif","/i/eg_2fdr.gif","/i/eg_3fdr.gif","/i/eg_4fdr.gif","/i/eg_5fdr.gif","/i/eg_6fdr.gif","/i/eg_7fdr.gif","/i/eg_8fdr.gif","/i/eg_9fdr.gif")
  7. time=new Date()
  8. hour=time.getHours()
  9. if (hour<10)
  10. {
  11. document.getElementById('hour1').src=num[0]
  12. h2="'" + hour + "'"
  13. h2=h2.charAt(1)
  14. document.getElementById('hour2').src=num[h2]
  15. }
  16. else
  17. {
  18. h1="'" + hour + "'"
  19. h1=h1.charAt(1)
  20. document.getElementById('hour1').src=num[h1]
  21. h2="'" + hour + "'"
  22. h2=h2.charAt(2)
  23. document.getElementById('hour2').src=num[h2]
  24. }
  25. minute=time.getMinutes()
  26. if (minute<10)
  27. {
  28. document.getElementById('minute1').src=num[0]
  29. m2="'" + minute + "'"
  30. m2=m2.charAt(1)
  31. document.getElementById('minute2').src=num[m2]
  32. }
  33. else
  34. {
  35. m1="'" + minute + "'"
  36. m1=m1.charAt(1)
  37. document.getElementById('minute1').src=num[m1]
  38. m2="'" + minute + "'"
  39. m2=m2.charAt(2)
  40. document.getElementById('minute2').src=num[m2]
  41. }
  42. second=time.getSeconds()
  43. if (second<10)
  44. {
  45. document.getElementById('second1').src=num[0]
  46. s2="'" + second + "'"
  47. s2=s2.charAt(1)
  48. document.getElementById('second2').src=num[s2]
  49. }
  50. else
  51. {
  52. s1="'" + second + "'"
  53. s1=s1.charAt(1)
  54. document.getElementById('second1').src=num[s1]
  55. s2="'" + second + "'"
  56. s2=s2.charAt(2)
  57. document.getElementById('second2').src=num[s2]
  58. }
  59. }
  60. function showTime()
  61. {
  62. timer=setTimeout("getDigits()",10)
  63. interval=setInterval("getDigits()",1000)
  64. }
  65. function stopInterval()
  66. {
  67. clearTimeout(timer)
  68. clearInterval(interval)
  69. }
  70. </script>
  71. </head>
  72.  
  73. <body onload="showTime()" onunload="stopInterval()" bgcolor="#000000">
  74. <img id="hour1" />
  75. <img id="hour2" />
  76. <img id="minute1" />
  77. <img id="minute2" />
  78. <img id="second1" />
  79. <img id="second2" />
  80. </body>
  81. </html>