Js timer delay

Source: Internet
Author: User

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<Html>
<Head>
<Title> New Document </title>
</Head>
<Body>
<Form action = "somepage. asp">
<Input type = "text" value = "0" name = "txt1"/>
<Input type = "button" value = "start" name = "btnStart"/>
<Input type = "button" value = "reset" name = "btnReset"/>
</Form>
</Body>
</Html>
<Script language = "JavaScript" type = "text/javascript">
<! --
// Obtain the form field in the form
Var txt = document. forms [0]. elements ["txt1"];
Var btnStart = document. forms [0]. elements ["btnStart"];
Var btnReset = document. forms [0]. elements ["btnReset"]
// Define the timer id
Var id;
// Increase the value by 1 every 10 milliseconds.
Var seed = 0;

BtnStart. onclick = function (){
// Determine the current operation based on the button text
If (this. value = "start "){
// Make the button text Stop
This. value = "stop ";
// Make the reset button unavailable
BtnReset. disabled = true;
// Set the timer to jump every 0.01 seconds
Id = window. setInterval (tip, 10 );
} Else {
// Change the button text to start
This. value = "start ";
// Make the reset button available
BtnReset. disabled = false;
// Cancel the timer
Window. clearInterval (id );
}
}

// Reset button
BtnReset. onclick = function (){
Seed = 0;
}
// Jump the stopwatch to a grid
Function tip (){
Seed ++;
Txt. value = seed/100;
}
// -->
</Script>

Related Article

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.