日期时间特效:网页秒表计时器

一个日期时间的JavaScript秒表计时器特效,很不错,点击开始就开始计时了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<html><head><title>blog.bcdon.com|网页秒表计时器</title><SCRIPT LANGUAGE="JavaScript"><!-- Begin
var ms = 0;
var state = 0;
function startstop() {
if (state == 0) {
state = 1;
then = new Date();
then.setTime(then.getTime() - ms);
} else {
state = 0;
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
   }
}
function swreset() {
state = 0;
ms = 0;
document.stpw.time.value = ms;
}
function display() {
setTimeout("display();", 50);
if (state == 1)  {now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
   }
}
// End --></SCRIPT><body onLoad="display()"><FORM NAME="stpw"><br />
开始计时:<INPUT TYPE="text" Name="time"><INPUT TYPE="BUTTON" Name="ssbutton" VALUE="开始/停止" onClick="startstop()"><INPUT TYPE="BUTTON" NAME="reset" VALUE="重置" onClick="swreset()"><br />
</FORM></body></html>

发表一条评论:

电子邮件地址不会被公开。 必填项已用*标注