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