例子,setTimeout实现一个简单的计时器。 <li>var c=0;<li>var t;<li>var timer_is_on=0;<li><p>//js计时器代码<li>function timedCount()<li>{<li>document.getElementById('txt').value=c;<li>c=c+1;<li>t=setTimeout("timedCount()",1000);<li>}<li><p>function doTimer()<li>{<li>if (!timer_is_on)<li> {<li> timer_is_on=1;<li> timedCount();<li> }<li>}<li> Click on the button above. The input field will count forever, starting at 0. 复制代码