简单的计时器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>计时器</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <input type="text" name="num" size="1" value="0" /> <input type="button" name="start" value="开始计时" onclick="sta();" /> <input type="button" name="pause" value="暂停计时" onclick="pau();" /> </form> <script language="javascript"> var flag=0; var timeID; function beg(){ var i=form1.num.value; i++; form1.num.value=i; timeID=setTimeout("beg()",1000); } function sta(){ if(flag==0){ beg(); flag=1; } } function pau(){ clearTimeout(timeID); flag=0;
} </script> </body> </html>