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