案例:JavaScript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
var c=0
5
var t
6
function timedCount()
7
{
8
document.getElementById('txt').value=c
9
c=c+1
10
t=setTimeout("timedCount()",1000)
11
}
12
13
function stopCount()
14
{
15
c=0;
16
setTimeout("document.getElementById('txt').value=0",0);
17
clearTimeout(t);
18
}
19
</script>
20
</head>
21
22
<body>
23
24
<form>
25
<input type="button" value="开始计时!" onClick="timedCount()">
26
<input type="text" id="txt">
27
<input type="button" value="停止计时!" onClick="stopCount()">
28
</form>
29
30
<p>请点击上面的“开始计时”按钮来启动计时器。输入框会一直进行计时,从 0 开始。点击“停止计时”按钮可以终止计时,并将计数重置为 0。</p>
31
32
</body>
33
34
</html>
35