Introduction of SetTimeout () and SetInterval () method _javascript Skills

Source: Internet
Author: User
Timer settimeout () and SetInterval () two are all JS functions of the timing function two a little different.

SetTimeout ():

Explanation in the JS manual: used to call a function or evaluate an expression after a specified number of milliseconds;

That is, execute after the set number of seconds is completed.

Experiment code (change body background color):
Copy Code code as follows:

settimeout (function () {
$ ("Body"). CSS ("Background", "Red");
},5000);

SetInterval ():

Explanation in the JS manual: Call a function or a calculation expression according to the specified period (in milliseconds). The function is called continuously until the Clearinterval () is called or the window is closed;

Execute your own effect code or function in the number of seconds you set.

Experimental code (a few seconds of experiment):
Copy Code code as follows:

<div class= "Clock" ></div>
<script>
var num = 0;
SetInterval (function () {$ (". Clock"). HTML (num++)},1000);
</script>

Summarize:

The settimeout () method executes the function after waiting for a specified time, and executes only one incoming handle function.

The SetInterval () method executes an incoming handle function after each specified interval, looping until the window or clearinterval () is closed.

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.