具體代碼如下:
<html> <head> <title>定時器0~9抽獎系統</title> <meta charset="UTF-8" /> <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("#start").click(function(){ fn(); timer = setInterval('fn()',200);//向DIV中填充內容 }); $("#stop").click(function(){ clearInterval(timer);//清除定時器 }); }); var i=0; function fn(){ $("#box").html(i); i++; if(i==10){ i=0; } } </script> </head> <body> <div> <button id="start" type="button">開始</button> <button id="stop" type="button">停止</button> </div> <br /> <div id="box" style="width:200px;height:100px;border:1px solid;line-height:100px;font-size:80px;text-align:center;"></div> </body> </html>以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助~如果有疑問大家可以留言交流,謝謝大家對錯新站長站的支持!
新聞熱點
疑難解答
圖片精選