先看下效果
话不多说上代码~
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>计时器</title> <script type="text/javascript"> var num=0; var i; function clockstart(){ document.getElementById(‘clock‘).value=num; num++; i=setTimeout("clockstart()",1000); } function clockstop(){ clearTimeout(i); } function clockclear(){ num=0; setTimeout("document.getElementById(‘clock‘).value=0",0); clearTimeout(i); } </script> </head> <body> <input type="text" id="clock" /><br/><br/> <input type="button" value="开始" onclick="clockstart()" /> <input type="button" value="停止" onclick="clockstop()" /> <input type="button" value="复位" onclick="clockclear()" /> </body> </html
时间: 2024-10-13 12:29:26