代码描述:JavaScript计时器效果。JavaScript计时器效果
计时器在很多场合都有应用,例如体育场上教练手中的计时器,下面介绍一下如何在网页中是实现计时器效果,不过这里没有教练手中的精确,精确度只能到秒。 代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.51qianduan.com/" /> <script type="text/javascript"> var c=0; var t; function timedCount() { document.getElementById('txt').value=c c=c+1 t=setTimeout("timedCount()",1000) } function stopCount() { clearTimeout(t) } window.onload=function() { var ostart=document.getElementById("start"); var ostop=document.getElementById("stop"); ostart.onclick=function(){timedCount()} ostop.onclick=function(){stopCount()} } </script> </head> <body> <form> <input type="button" value="开始计时" id="start"/> <input type="text" id="txt"> <input type="button" value="停止计时" id="stop"> </form> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能