The use of JS timer

Source: Internet
Author: User
Tags setinterval

  This article mainly introduces the use of the timer in JS. Need friends can come to the reference, I hope to help you.

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>   code is as follows: < ! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head runat=" Server ">     <title> Untitled page</title>       <script language= "javascript" type= "Text/javascript" >   & nbsp var YC = new Object ();     function Beginyc ()     {        var secondsyc = document.getElementById ("Txty Cseconds "). Value;         try         {              YC = settime Out ("alert (' Delay" +secondsyc+ "second Success ')", secondsyc*1000);        }         catch (e)         {      &NBS P     Alert ("Please enter the correct number of seconds.") ");        } &NBSp  }     function overyc ()     {        cleartimeout (YC);     &NBSP ;   Yc=null;         alert ("Termination delay succeeded.") ");    }  /**************************↓↓↓↓ timer usage ↓↓↓↓********************************/      var timerds = new Object ();     var timerdds = new Object ();     function beginds ()     {        sn.innerhtml = "0";       &NBS P Timerds = SetInterval ("AddOne ()", parseint (document.getElementById ("Txtintervalseconds"). value,10) *1000);    }     function goonds ()     {        timerds = setinterval ("AddOne" ( ) ", parseint (document.getElementById (" Txtintervalseconds "). value,10) *1000);    }     function overds ()     {        clearinterval (timerds);         Timerds=null;    }     FUNCTIon Delayds ()     {        overds ();         Timerdds = settimeout ("Goo NDS () ", document.getElementById (" Txtddsseconds "). value*1000);    }     function AddOne ()     {        if (sn.innerhtml== ")         {          overds ()        ,     alert ("Congratulations, has been successfully reached 10 seconds");             return;        }         Sn.innerhtml=parseint (sn.innerhtml,10) +1;    }       </script>   </head> <body>     <form id= "Form1" R unat= "Server" >     <div>         delay using:</div>     <div> &nbs P    <label id= "Label2" title= "delay seconds:" ></label>         <input type= "text" id= "Txtycseconds" value= "3"/>        <input type= "button" id= "BTNBYC" onclick= "Javascript:beginyc ()" value= "Start delay"/>         <input type= "button" id= "Btnoyc" onclick= "Javascript:overyc ()" value= "termination delay"/>       & nbsp <input type= "button" id= "Button1" onclick= "Javascript:alert (' good monrning ');" value= "regular window"/>     < /div>     <br/>     <div>         timer usage:</div>   &NBSP ; <div>     <div id= "SN" >0</div>     <label id= "Label1" title= "timed interval seconds:" ></ label>         <input type= "text" id= "Txtintervalseconds" value= "1"/>       & nbsp <input type= "button" id= "Btnbds" onclick= "Javascript:beginds ()" value= "Start timed"/>         < Input type= "button" id= "Btnods" onclick= "Javascript:overds ()" value= "Terminate timed"/>         <input Ty Pe= "button" id= "Btngds" Onclick= "Javascript:goonds ()" value= "Continue timed"/>           <label id= "DS" title= "Delay seconds:" >& lt;/label>         <input type= "text" id= "Txtddsseconds" value= "5"/>       &N Bsp <input type= "button" id= "Btndds" onclick= "javascript:delayds ()" value= "Delay timed"/>           </div>     </form> </body> </html>  

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.