SetTimeout and SetInterval different detailed

Source: Internet
Author: User
Tags setinterval time interval
settimeout ("Showresponse" (' ${rooturl}index/movie.do ', ' MovieID ') ", 400);
SetInterval ("Showresponse" (' ${rooturl}index/newwarn.do ', ' Newwarntd ') ", 10000);
settimeout ("Showresponse" (' ${rooturl}index/movie.do ', ' MovieID ') ", 400);
SetInterval ("Showresponse" (' ${rooturl}index/newwarn.do ', ' Newwarntd ') ", 10000);


The Window object has two main timing methods, settimeout and Setinteval, whose syntax is essentially the same, but the completed functionality differs.

The SetTimeout method is the timer program, which is what to do after the time. Just finish it.

The SetInterval method is to indicate that an operation is repeated at a certain time interval.

If you implement the function of Setinerval with settimeout, you need to call yourself in the program you are executing. If you want to clear the counter you need to invoke different cleanup methods depending on the method you are using:


1) settimeout (expression, delay time)
At execution time, after the specified time is delayed, the expression is executed once, remembering that the number is once

The effect of displaying random number with automatic change realized by settimeout

<script>
Window.onload=sett;
function Sett ()
{
Document.body.innerhtml=math.random ();
settimeout ("Sett ()", 500);
}
</script>
<body>
</body>

2) setinterval (expression, interaction time)
is not the same, it executes an expression once at a specified time from loading

Automatic changes with setinterval to display the effect of random numbers:

HTML code

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.