标签:
<!DOCTYPE html> <html> <head> <title>json</title> <script type="text/javascript"> function show(){ alert("a"); } //每隔1s执行一次函数 setInterval(show, 1000); </script> </head> <body> </body> </html>
<!DOCTYPE html> <html> <head> <title>json</title> <script type="text/javascript"> function show(){ alert("a"); } //1s之后执行该函数且只执行一次 setTimeout(show, 1000); </script> </head> <body> </body> </html>
<!DOCTYPE html> <html> <head> <title>json</title> </head> <body> <button type="button" id="open">开启</button> <button type="button" id="close">关闭</button> <script type="text/javascript"> function show(){ alert("a"); } var oBtn1 = document.getElementById(‘open‘); var oBtn2 = document.getElementById(‘close‘); var timer = null; oBtn1.onclick=function (){ timer = setInterval(show, 1000); } oBtn2.onclick = function (){ clearInterval(timer); } </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/xidongyu/p/5487643.html