Difference between setinterval and setTimeout

Source: Internet
Author: User

Note:
Setinterval and setTimeout are both dhtm window objects.

Differences:
Setinterval (expression, Time): After a page is loaded, the specified expression is executed every time after a specified millisecond value.
SetTimeout (expression, Time): After a page is loaded, the specified expression is executed only once after a specified millisecond value.

Appendix:
You can use the clearInterval and clearTimeout methods to cancel events. For more information, see the DHMTL manual.

The test code is as follows:

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<SCRIPT>
VaR Index = 0;
VaR Si;
Function Test (){
VaR test = Document. getelementbyid ("mydiv"). innerhtml;
Index ++;
Test + = index + "<br> ";
Document. getelementbyid ("mydiv"). innerhtml = test;
If (Index = 10 ){
Clearinterval (SI );
}
}
SI = setinterval (test, 1000 );
// SetTimeout (test, 1000 );
</SCRIPT>
</Head>
<Body>
<Div id = "mydiv"> </div>
</Body>
</Html>

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.