标签:class var strong str name onclick col window bsp
setTimeout是指过多久执行,只执行一次
setInterval是指每过多久执行一次
clearTimeout是关闭setTimeout定时器
clearInterval是关闭setInterval定时器,不让它一直执行
<html> <head> <title></title> </head> <style> </style> <script> window.onload=function(){ var aButton=document.getElementsByTagName("input") var timer="" var inter="" aButton[0].onclick=function(){ debugger inter=setInterval(function(){ alert("1") },1000) } aButton[1].onclick=function(){ clearInterval(inter) } aButton[2].onclick=function(){ timer=setTimeout(function(){ alert("1") },1000) } aButton[3].onclick=function(){ clearTimeout(timer) } } </script> <body> <input type="button" value="开启Interval" /> <input type="button" value="关启Interval"/> <input type="button" value="开启timeout"/> <input type="button" value="关启timeout"//> </body> </html>
JS中定时器setTimeout,setInterval,clearTimeout,clearInterval用法
标签:class var strong str name onclick col window bsp
原文地址:https://www.cnblogs.com/superCwen/p/9807572.html