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.
Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.