How to Write a js timer? Is to execute a certain segment of program _ javascript skills at a specific time.

Source: Internet
Author: User
The timer MUST be familiar to everyone. In this article, we will introduce in detail how to implement the timer in js. The specific principle and code are as follows. Do not miss it if you are interested. The Code is as follows:


$ (Function (){
Var handler = function (){

}
Var timer = setInterval (handler, 1000 );

Var clear = function (){
ClearInterval (timer );
}
});


I want to add a page Jump in the timer and load the timer when loading the page. How to write it?

The implementation is like how many messages are prompted at the place where Baidu initiates instant messages. The method for querying the number of items in java is available. How to Write JavaScript?

Timer:

It is used to execute a program after a specific period of time.

Regular execution in JS, difference between setTimeout and setInterval, and l release method

SetTimeout (Expression, DelayTime): After DelayTime, an Expression is executed. setTimeout is used for a delay period before a certain operation.
SetTimeout ("function", time) sets a timeout object

SetInterval (expression, delayTime). Expression is executed for each DelayTime. It is often used to refresh an expression.
SetInterval ("function", time) sets a timeout object

SetInterval indicates automatic repetition, and setTimeout does not.

ClearTimeout (object) clears the set setTimeout object
ClearInterval (object) clears the set setInterval object

The Code is as follows:


SetTimeout (aa (), 1000) // unit: milliseconds
Function aa ()
{
Location. href ('address ');
}

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.