Use SetTimeout () to implement a countdown effect code instance

Source: Internet
Author: User

Use SetTimeout () to implement the countdown effect code instance:
In most cases, the countdown effect is to use the setinterval () function, because this function can execute a specified function once every specified implementation, whereas the settimeout () function can only be executed once, but it can also achieve a countdown effect. Here's a code example that shows how to use the settimeout () function to achieve a countdown effect.
The code example is as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><Scripttype= "Text/javascript"> functiontimer () {varvalue=Number (document.all['Timer'].value); if(Value>1) {document.all['Timer'].value=value-1; }   Else{document.all['Timer'].value="Agree"; return false; } window.settimeout ("timer ()", +); } window.onload=function() {timer ()}</Script> </Head> <Body> <inputname= "Timer"value= "Ten"type= "button"/> </Body> </HTML>

The above code to achieve our requirements, you can use the settimeout () function to achieve the countdown effect, although settimeout () can only be executed once, but the use of recursive way, constantly call itself, you can achieve the countdown effect, the specific implementation of the process here more introduction, You can refer to the related readings.
Related reading:
The 1.Number () function can refer to the number () method section of JavaScript .
The 2.setTimeout () function can be found in the SetTimeout () Method section of the Window object .
3.document.all can refer to the document.all usage section of JavaScript.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=11519

For more information, refer to: http://www.softwhy.com/javascript/

Use SetTimeout () to implement a countdown effect code instance

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.