The Window.setinterval () method invokes a function or evaluates an expression according to the specified period (in milliseconds).
Window.clearinterval () method to cancel SetInterval () Window.clearinterval ()
The parameter of the method must be the ID value returned by SetInterval ().
#
Real-time display date:
var i=0; function ABC () { var mytime=New Date (); var mydiv=document.getelementbyid (' abc '); Mydiv.innertext=mytime.tolocalestring (); if (++i==5) { window.clearinterval (res);} } var res=window.setinterval ("ABC ()", 1000);
#
You can also use a button to turn on the timer and turn off the timer
<! DOCTYPE html>vararr; functionW () {arr=window.setinterval ("Clock ()"); } functionclock () {vart=NewDate (); varWang=document.getelementbyid ("Clock"); Wang.innertext=t.tolocalestring (); } </script>The current time is:<span id= "Clock" ></span> <input onclick= "Window.clearinterval (arr)" type= "button" value= "Stop Timer" > & Lt;input onclick= "W ()" Type= "button" value= "Start Timer" ></body>
#
Number of seconds using timers:
<! DOCTYPE html>vari=10; functionCounttime () {i--; Mybut.value= "Agree" +i; if(i==0) { //make this button availableMybut.disabled=false; Window.clearinterval (MyTimer); Mybut.value= "Agree"; } } varMytimer=window.setinterval ("Counttime ()", 1000);</script>SetInterval () and settimeout ()