数字时钟 [Digital Clock]

clockclockclockclockclockclock
开始 | 暂停 | 停止

代 码:

<html>
<head>
<title>生动逼真的数字时钟</title>
<script language="JavaScript">
<!--
img = new Array()
for(var i=0; i <= 14; i++) {img[i] = new Image()}
img[1].src = "dg0.gif"
img[2].src = "dg1.gif"
img[3].src = "dg2.gif"
img[4].src = "dg3.gif"
img[5].src = "dg4.gif"
img[6].src = "dg5.gif"
img[7].src = "dg6.gif"
img[8].src = "dg7.gif"
img[9].src = "dg8.gif"
img[10].src = "dg9.gif"
img[11].src = "dgon.gif"
img[12].src = "dgoff.gif"
img[13].src = "dgam.gif"
img[14].src = "dgpm.gif"
var base = "dg"
var space = "space.gif"

var per = false
function stop()
{
 document.one.src = space
 document.two.src = space
 document.three.src = space
 document.four.src = space
 document.five.src = space
 document.six.src = space
 per = false
}
function pause() {per = false}
function go()
{
 per = true
 start()
}
function start()
{
if(per == true) {
var now = new Date()
var hours = now.getHours();
var ampm = (hours < 12) ? "am" : "pm"
hours = (hours > 12) ? (hours - 12) + "" : hours + ""
hours = (hours == "0") ? "12" : hours
hours = (hours < 10) ? "0" + hours : hours + ""
var minutes = now.getMinutes();
minutes = (minutes < 10) ? "0" + minutes : minutes + ""
var seconds = now.getSeconds();
seconds = (seconds < 10) ? "0" + seconds : seconds + ""
document.one.src = (hours.charAt(0)=="0") ? space : add(hours.charAt(0))
document.two.src = add(hours.charAt(1))
document.three.src = (now.getSeconds() % 2) ? add("on") : add("off")
document.four.src = add(minutes.charAt(0))
document.five.src = add(minutes.charAt(1))
document.six.src = add(ampm)
setTimeout("start()",1000)
}
}

function add(it){ return "dg" + it + ".gif"}
//-->
</script>
</head>

<body onLoad="go()" bgcolor="#000000" text="#FFFFFF">
<img src="space.gif" width=16 height=21 alt="clock" name="one"><img src="space.gif" width=16 height=21 alt="clock" name="two"><img src="space.gif" width=14 height=21 alt="clock" name="three"><img src="space.gif" width=16 height=21 alt="clock" name="four"><img src="space.gif" width=16 height=21 alt="clock" name="five"><img src="space.gif" width=16 height=21 alt="clock" name="six">
<br>
<a href="javascript:go()">开始</a> | <a href="javascript:pause()">pause</a> | 
<a href="javascript:stop()">stop</a>
</body>
</html>

说明:图片文件名应该是dg0.gif,dg1.gif...,你可以用自己的图片替换它们。<BODY>标签中的onLoad="go()"千万不要少,否则不会运行的。

黄色部分代码是时钟初始设置,写成一行,这样数字之间不会留空格。



Copyright(C) By 西安网e工作室 关闭本窗口
站长邮箱:zhangking@263.net   Bp:029-95808 呼 822686    O'ICQ:9365822