<html> <head> <title>test</title> <meta charset="UTF-8"/> <script type="text/javascript"> var a=0; var t; function f () { document.getElementById("di").value=a; a++; t=setTimeout("f()",1000); } function ff () { document.getElementById("di").value=a; clearTimeout(t); } function fff () { document.getElementById("di").value=0; clearTimeout(t); a=0; } </script> </head> <body> <button onclick="f()">click</button> <input id="di" type="text" value=0> <button onclick="ff()">stop</button> <button onclick="fff()">again</button> </body> </html>