JS Timer Application

Source: Internet
Author: User

  • Timer:(delay device)
    Used to specify that a program executes after a specific period of time.
  • setTimeout ():(version 1.0)

  • Format:
    [Timer Object name =] SetTimeout ("< expression >", ms)
    Function: Execute < expression > once.

    <script language= "JavaScript" >
    SetTimeout ("Confirm (' 123456 ')", 1000);
    </SCRIPT>
    <script language= "JavaScript" type= "Text/javascript" >
    function count () {
    SetTimeout ("alert (' three Seconds to ')", 3000)
    }
    </Script>
    <input type= "button" value= "timing Start" onclick= "Count ()" >
  • cleartimeout (): Termination timer

  • Format:
    Cleartimeout (Timer object name)
  • setinterval ():(Version 1.2)

  • Format:
    [Timer Object name =] SetInterval ("< expression >", ms)
    Function: Repeat execution < expression, until window, frame is closed or execution clearinterval.
  • clearinterval (): Termination timer

  • Format:
    Clearinterval (Timer object name)


    Example 1:
    <script><script language= "JavaScript" type= "Text/javascript" >
    var sec = 0;
    Timerid = SetInterval ("Count ()", 1000);
    function count () {
    num.innerhtml = sec++;
    }
    </Script>
    Stay time:
    <font id= "num" face= "impact" >0</FONT> seconds
    <input type= "button" value= "Stop" onclick= "Clearinterval (Timerid)" >
    Example 2:
    <script language= "JavaScript" type= "Text/javascript" >
    var str = "This is an online auction site, please enjoy the blood!" ";
    var seq = 0;
    function Scroll () {
    msg = str.substring (0, seq+1);
    banner.innerhtml = msg;
    seq++;
    if (seq >= str.length) seq = 0;
    }
    </Script>
    <body onload= "setinterval (' scroll () ',") ">
    <font id= "banner" ></FONT>

JS Timer Application

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.