Introduction and application of JS settimeout () function with countdown as an example

Source: Internet
Author: User

The settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds, and there is an example of a countdown that needs a friend to learn

Definition and Usage: the settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.  Syntax: settimeout (code,millisec) Parameter: code (required): The JavaScript code string to execute after the function to be invoked.    Millisec (required): The number of milliseconds to wait before executing code. Tip: settimeout () executes only one code at a time.    If you want to call more than once, use SetInterval () or let code itself call SetTimeout () again.  For example: The code is as follows: <script language= "JavaScript" > function timer () {var value=number (document.all[' time '].value);  if (value>1) document.all[' time '].value=value-1;  else {document.all[' time '].value= "agreed";  return false;    } window.settimeout ("Timer ()", 1000); } </script> <body onload= "timer ()" > <input name= "Time" value= "" type= "button" style= "width:40px"/>  ; </body>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.