我为Javascript计时器编写了以下代码并进行了一些验证。
function timedcounter(){
time=time+1;
t = setTimeout(function(){ timedcounter() }, 1000);
display(time);
}
function starttimer() {
var autotask=document.getElementById("Tasks").value
if(autotask=="") {
$("#errormsg2").show();
} else {
if(!timer_is_on){
add_row_flag=1;
var value=document.getElementById("startstopbutton").value
if(value=="Start") {
timer_is_on=1;
value="Stop";
document.getElementById("startstopbutton").innerHTML="Stop"
$("#errormsg2").hide();
timedcounter();
}
} else {
add_row_flag=0;
stoptimer();
}
}
}
function stoptimer(){
clearTimeout(t);
timer_is_on=0;
document.getElementById("startstopbutton").innerHTML="Start"
document.getElementById("disptime").value=null;
finaltime(time);
time=-1;
}
我想知道是否有任何方法可以在用户关闭浏览器后保持计时器运行,例如当他重新打开网页计时器时应显示自启动计时器以来经过的时间。
答案 0 :(得分:1)
您有三种选择: