SetInterval () and settimeout ()

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.