如何使倒数计时器普及 [英] How to make count down timer universal

查看:86
本文介绍了如何使倒数计时器普及的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个倒数计时器,一旦它结束15分钟的新倒计时将有15分钟的跨度。

问题是,当我刷新页面时它也会刷新。亲切地告诉我如何让它变得普及。



我尝试过:



< script type =text / javascript>



var timeInSecs;

var ticker;



函数startTimer(秒){

timeInSecs = parseInt(secs);

ticker = setInterval(tick() ,1000);

}



函数tick(){

var secs = timeInSecs;

if(secs> 0){

timeInSecs--;

}

else {

clearInterval(自动收报机);

startTimer(900); //重新开始

}



var hours = Math.floor(secs / 3600);

secs %= 3600;

var mins = Math.floor(secs / 60);

secs%= 60;

var pretty =((小时< 10)?0:)+小时+:+((分钟< 10)?0:)+分钟+:+((秒<10)? 0:)+秒;

document.getElementById(倒计时)。innerHTML =漂亮;

}



startTimer(900); // 15分钟秒



< / script>

i have a countdown timer,which has the span of 15 minutes once it end a new countdown of 15 minute will start.
the problem is that when ever i refresh page it also get refreshed.so kindly tell me how to make it universal.

What I have tried:

<script type = "text/javascript">

var timeInSecs;
var ticker;

function startTimer(secs) {
timeInSecs = parseInt(secs);
ticker = setInterval("tick()", 1000);
}

function tick() {
var secs = timeInSecs;
if (secs > 0) {
timeInSecs--;
}
else {
clearInterval(ticker);
startTimer(900); // start again
}

var hours = Math.floor(secs / 3600);
secs %= 3600;
var mins = Math.floor(secs / 60);
secs %= 60;
var pretty = ((hours < 10) ? "0" : "") + hours + ":" + ((mins < 10) ? "0" : "") + mins + ":" + ((secs < 10) ? "0" : "") + secs;
document.getElementById("countdown").innerHTML = pretty;
}

startTimer(900); // 15 minutes in seconds

</script>

推荐答案

如评论中所述,您必须将值存储在某处,以便在页面加载时可以检查计时器是否为当前正在运行,然后从那里开始编码。
As mentioned in comments, you'll have to store the value somewhere so that when the page loads you can check if the timer is currently running and then code from there.


这篇关于如何使倒数计时器普及的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆