The difference between settimeout and setinterval

Source: Internet
Author: User

The difference between settimeout and setinterval

Code

SetTimeout ("Showresponse (' ${rooturl}index/movie.do ', ' MovieID ')", 400);

SetInterval ("Showresponse (' ${rooturl}index/newwarn.do ', ' Newwarntd ')", 10000);

The Window object has two main timing methods, namely settimeout and setinteval their syntax is basically the same, but the completed function is different.

The SetTimeout method is a timed procedure, that is, what to do after what time. When you're done.

The SetInterval method is to represent the interval for a certain amount of time to perform an operation repeatedly.

SetTimeout ("Todo ()", 1000) means that TODO () is automatically executed once in 1 seconds (1000 milliseconds).

SetInterval ("Todo ()", 1000) refers to the automatic execution of TODO () every 1 seconds. It is a constant interval loop.

If you implement Setinerval functionality with settimeout, you will need to call yourself again and again in the program you are executing. If you want to purge counters that need to be different from the method used, call different cleanup methods:

1) setTimeout (expression, delay time)

At execution time, after the load is delayed for a specified period, the expression is executed once, remembering that the number of times is

Automatic changes implemented with settimeout show the effect of random numbers:

Code

<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 the expression once every specified time from loading

Automatic changes implemented with SetInterval show the effect of random numbers:

Code

<script>

function Sett ()

{

Document.body.innerhtml=math.random ();

}

SetInterval ("Sett ();", 500);

</script>

</script>

<body>

</body>

The difference between settimeout and setinterval

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.