This article mainly introduces the relevant information of javascript timer in detail. It is very comprehensive and detailed. Friends in need can refer to
Timer
Basic format:
The code is as follows:
setInterval(function(){代码},1000); /* 说明:1.setInterval 会返回一个计时器ID值 可以这样接收。var setId = setInterval(....); 2.接收setId的目的是为了清空计时器。 clearTimeout(setId); */
For example
One-time timer
Format:
The code is as follows:
setTimeout(function(){代码},1000)
Case:
The code is as follows:
var setId = setTimeout(function(){ alert('只执行一次'); },1000);
Title scrolling case
The code is as follows:
setInterval(function(){ var tit = document .title; //1~length + 0 document.title = tit.sub string (1)+tit. substr ing(0,1); },1000);
The above is the detailed content of Detailed explanation of JS timer function examples. For more information, please follow other related articles on the PHP Chinese website!