实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<script>
5
var c=0;
6
var t;
7
var timer_is_on=0;
8
9
function timedCount()
10
{
11
document.getElementById('txt').value=c;
12
c=c+1;
13
t=setTimeout("timedCount()",1000);
14
}
15
16
function doTimer()
17
{
18
if (!timer_is_on)
19
  {
20
  timer_is_on=1;
21
  timedCount();
22
  }
23
}
24
</script> 
25
</head>
26
27
<body>
28
<form>
29
<input type="button" value="Start count!" onClick="doTimer()">
30
<input type="text" id="txt">
31
</form>
32
<p>Click on the button above. The input field will count forever, starting at 0.</p>
33
</body>
34
</html>