JSTiming _ basic knowledge

Source: Internet
Author: User
Using JS, JSTiming enables function execution not directly, but after a specified interval. This is called an event.
With JavaScript, it is possible to execute some code NOT immediately after a function is called, but after a specified time interval. This is called timing events.
Using JS allows the function to be executed not directly, but only after a specified interval. This is called an event.
JavaScript Timing Events
JS time event
With JavaScript, it is possible to execute some code NOT immediately after a function is called, but after a specified time interval. This is called timing events.
Using JS allows the function to be executed not directly, but only after a specified interval. This is called an event.
It's very easy to time events in JavaScript. The two key methods that are used are:
JS time events are very simple. Two key methods are used:
* SetTimeout ()-executes a code some time in the future
Execute the code after some time
* ClearTimeout ()-cancels the setTimeout ()
Cancel setTimeout ()
Note: The setTimeout () and clearTimeout () are both methods of the html dom Window object.
Note: setTimeout () and Timeout () are both methods of html dom Window objects.
SetTimeout ()
Syntax
Var t = setTimeout ("javascript statement", milliseconds)
The setTimeout () method returns a value-In the statement above, the value is stored in a variable called t. if you want to cancel this setTimeout (), you can refer to it using the variable name.
The setTimeout () method returns a value-in the preceding Declaration, the value is saved in variable t. If you want to cancel this setTimeout (), you can use the variable name to propose it (clearTimeout (t ))
The first parameter of setTimeout () is a string that contains a JavaScript statement. This statement cocould be a statement like "alert ('5 seconds! ') "Or a call to a function, like" alertMsg ()".
The first parameter of setTomeout () is the string declaration. It can be like "alert ('5 seconds! ') "Or call a function like" alertMsg ()"
The second parameter indicates how many milliseconds from now you want to execute the first parameter.
The second parameter is used to indicate how many milliseconds you want to execute the first parameter from now on
Note: There are 1000 milliseconds in one second.
1000 milliseconds for one second
Example
Example
When the button is clicked in the example below, an alert box will be displayed after 5 seconds.
After the button is clicked, a warning box is displayed every five seconds.


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.