Home > Web Front-end > JS Tutorial > body text

js timer

巴扎黑
Release: 2016-12-06 10:09:54
Original
1380 people have browsed it

js can use two timers, one is setInterval (function(){}, time); the other is setTimeout (function(){}, time);

The difference between the two is that setInterval is not set after time milliseconds. Execute a function once, settimeout is to execute the function after time milliseconds,

I encountered a problem here,

Js code

function startFlushTime(min){  
    var sec = min*60 ;  
    var time = timeFormat(sec) ;  
    $("#time").html(time);  
    setInterval(doflush(), 1000);  
}  
function doflush(){  
    debugger  
    var time = $("#time").html();  
    if(time && time!=''){  
        var res = timeFormat(timeParse(time)-1)  
        $("#time").html(res);  
    }  
}
Copy after login

will not execute the scheduled task after writing it like this, change it to

Js code

function startFlushTime(min){  
    var sec = min*60 ;  
    var time = timeFormat(sec) ;  
    $("#time").html(time);  
    setInterval(function(){doflush();}, 1000);  
}  
function doflush(){  
    debugger  
    var time = $("#time").html();  
    if(time && time!=''){  
        var res = timeFormat(timeParse(time)-1)  
        $("#time").html(res);  
    }  
}
Copy after login

and succeed, that is, setinterval Then create a new function and execute the methods that need to be executed in it


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template