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>