JavaScript Timer detailed _javascript tips

Source: Internet
Author: User

Timer

Basic format:

Copy Code code as follows:

SetInterval (function () {code},1000);

/*

Description: 1.setInterval Returns a timer ID value

can receive this way. var setId = setinterval (...);

2. The purpose of receiving setid is to clear the timer.

Cleartimeout (SETID);

*/

For example


a one-time timer

Format:

Copy Code code as follows:

settimeout (function () {code},1000)

Case:

Copy Code code as follows:

var setId = settimeout (function () {
Alert (' Execute only once ');
},1000);

Title Scrolling case

Copy Code code as follows:

SetInterval (function () {
var tit =document.title;
1~length + 0
Document.title = tit.substring (1) +tit.substring (0,1);
},1000);

I hope that the small partners through this article can have a new understanding of JavaScript timer, if you have questions, give me a message.

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.