Usage of javascript timer events _ basic knowledge

Source: Internet
Author: User
By using JavaScript, code can be executed after a set interval, rather than immediately after the function is called. We call it a timing event. Next we have explained in detail the javascript timer event. It is very easy to use the timing event in javascrui. The two key methods are as follows:

SetTimeout ()
Execute Code at a certain time in the future

ClearTimeout ()
Cancel setTimeout ()
SetTimeout ()
Syntax

The Code is as follows:


Var t = setTimeout ("javascript statement", millisecond)



The setTimeout () method returns a value. In the preceding statement, the value is stored in the variable t. If you want to cancel this setTimeout (), you can use this variable name to specify it.
The first parameter of setTimeout () is a string containing JavaScript statements. This statement may be like "alert ('5 seconds! ') ", Or call a function, such as alertMsg ()".

The second parameter indicates how many milliseconds since the current time the first parameter will be executed.

Tip: 1000 milliseconds equals one second.

When the button in the following example is clicked, a prompt box will pop up in five seconds.

The Code is as follows:




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.