js实例(setInterval, clearInterval)

xiaoxiao2021-02-28  95

<html> <meta charset="utf-8"> <head> <title>jquery</title> <script type="text/javascript" src="jquery-1.11.0.min.js"></script> <script type="text/javascript"> var i=1; var _interval; function showTime() { var today = new Date(); $("#msg").html(today.toLocaleString() + ",i=" + i); i++; if (i>10) { clearInterval(_interval); } } $(document).ready(function(){ $("#btnStart").click(function(){ showTime(); _interval = setInterval("showTime()", 1000);#1S触发一次showTime }) $("#btnStop").click(function(){ clearInterval(_interval);#停止记时 i=0; }) }) </script> </head> <body> <label id="msg">xx</label>  <button id="btnStart">开始记时</button>  <button id="btnStop">停止记时</button> <script type="text/javascript"> </script> </body> </html>
转载请注明原文地址: https://www.6miu.com/read-63041.html

最新回复(0)