<!doctype html> <html> <head> <meta set="utf-8"> <title>setInterval的停止与启动</title> </head> <body> <h3 id="z"></h3> <input type="button" value="停止" onClick="tz()"><input type="button" value="启动" onClick="qd()"> <script> var i=0; function func() { document.getElementById('z').innerHTML = i++; } //定时任务 var interval = setInterval(func, 1000); //启动,func不能使用括号 function tz() { clearInterval(interval); //停止 } function qd() { interval = setInterval(func, 1000); //重新启动即可 } </script> </body> </html>