Window.setinterval () periodically invokes a function or executes a piece of code.
1 var intervalid = window.setinterval (func, delay[, param1, param2, ...]); 2 var intervalid = window.setinterval (code, delay); Not recommended
Window.clearinterval () cancels setInterval the recurring action with the set .
1 window.clearinterval (intervalid)
Instance:
1<script type= "Text/javascript" >2$ (document). Ready (function(){3 //Method One4 varNINTERVID1 = SetInterval (Flashtext, 2000);5 //Method A6 varNINTERVID2 = SetInterval ("Flashtext ()", 2000);7 //Not recommended8 varNINTERVID3 = SetInterval ("Console.log (' Hello world! ')", 3000);9 // Ten varNIntervId4 = SetInterval (function(){ OneConsole.log ("Hello boyy!"); A},3000); - //Clear - clearinterval (NINTERVID1); the }); - // - functionFlashtext () { -Console.log ("Exec function Flashtext ()"); + } -</script>
Window.settimeout call a function or execute a code fragment after the specified delay time .
var timeoutid = window.settimeout (func, delay, [param1, Param2, ...]); var timeoutid = window.settimeout (code, delay); Not recommended
window.clearTimeout() 取消掉用setTimeout设置的重复执行动作。
1 Window.clearinterval (Timeoutid)
JS Timer Method SetInterval (), SetTimeout ()