Js timer usage (example)

Source: Internet
Author: User

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
Copy codeThe 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">
Var YC = new Object ();
Function beginYC ()
{
Var secondsYC = document. getElementById ("txtYCSeconds"). value;
Try
{
YC = setTimeout ("alert ('latency" + secondsYC + "second successfully')", secondsYC * 1000 );
}
Catch (e)
{
Alert ("enter the correct number of seconds. ");
}
}
Function overYC ()
{
ClearTimeout (YC );
YC = null;
Alert ("delay terminated successfully. ");
}

/************************** Use of the timer, timer, and timer ** ******************************/

Var timerDS = new Object ();
Var timerDDS = new Object ();
Function beginDS ()
{
Sn. innerHTML = "0 ";
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 ("goonDS ()", document. getElementById ("txtDDSSeconds"). value * 1000 );
}
Function addOne ()
{
If (sn. innerHTML = "10 ")
{
OverDS ();
Alert ("congratulations, it has been successfully set to 10 seconds ");
Return;
}
Sn. innerHTML = parseInt (sn. innerHTML, 10) + 1;
}

</Script>

</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Use of delimiters: </div>
<Div>
<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 = "End Delay"/>
<Input type = "button" id = "Button1" onclick = "javascript: alert ('good monrning');" value = "normal pop-up window"/>
</Div>
<Br/>
<Div>
Timer usage: </div>
<Div>
<Div id = "sn"> 0 </div>
<Label id = "Label1" title = "scheduled interval seconds:"> </label>
<Input type = "text" id = "txtIntervalSeconds" value = "1"/>
<Input type = "button" id = "btnBDS" onclick = "javascript: beginDS ()" value = "Start Time"/>
<Input type = "button" id = "btnODS" onclick = "javascript: overDS ()" value = "timed termination"/>
<Input type = "button" id = "btnGDS" onclick = "javascript: goonDS ()" value = "Continue timing"/>

<Label id = "ds" title = "delay seconds:"> </label>
<Input type = "text" id = "txtDDSSeconds" value = "5"/>
<Input type = "button" id = "btnDDS" onclick = "javascript: delayDS ()" value = "delayed timing"/>

</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.