Introduction to the difference between settimeout () and SetInterval () method

Source: Internet
Author: User
Tags manual setinterval

Timer settimeout () and SetInterval () two are JS timer function of the function two some differences, the following for you to briefly introduce, I hope to help you

Timer settimeout () and SetInterval () two are all JS functions of the timing function two a little different.    SetTimeout (): The explanation in the JS manual: To call a function or evaluate an expression after a specified number of milliseconds, that is, to execute after the set number of seconds is completed.  Experimental code (change body background color): The code is as follows: settimeout (function () {$ ("body"). CSS ("Background", "Red");    },5000); SetInterval (): In the JS manual explains: 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, and the number of seconds you set will execute your own effect code or function.  Experimental code (a few seconds of experiment): The code is as follows: <div class= "Clock" ></div> <script> var num = 0;  SetInterval (function () {$ (". Clock"). HTML (num++)},1000);    </script> Summary: 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.
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: and provide relevant evidence. A staff member will contact you within 5 working days.