Javascript 计时器不会在00:00停止

Javascript 计时器不会在00:00停止,javascript,timer,countdown,Javascript,Timer,Countdown,我的倒计时计时器不会停止00:00,它只是一直运行,直到到达“-01:59”然后“-02:59”等等,我在这里和那里更改了一些代码,但它仍然继续运行 <html> <head> <title>Countdown</title> <script type="text/javascript"> // set minutes var mins = 1; // calculate the second

我的倒计时计时器不会停止00:00,它只是一直运行,直到到达“-01:59”然后“-02:59”等等,我在这里和那里更改了一些代码,但它仍然继续运行

<html>

<head>
    <title>Countdown</title>
    <script type="text/javascript">
    // set minutes
    var mins = 1;

    // calculate the seconds (don't change this! unless time progresses at a      different speed for you...)
    var secs = mins * 60;

    function countdown() {
        setTimeout('Decrement()', 1000);
    }

    function Decrement() {
        if (document.getElementById) {
            minutes = document.getElementById("minutes");
            seconds = document.getElementById("seconds");
            // if less than a minute remaining
            if (seconds < 59) {
                seconds.value = secs;
            } else {
                minutes.value = getminutes();
                seconds.value = getseconds();
            }
            secs--;
            setTimeout('Decrement()', 1000);
        }
    }

    function getminutes() {
        // minutes is seconds divided by 60, rounded down
        mins = Math.floor(secs / 60);
        return ("0" + mins).substr(-2);
    }

    function getseconds() {
        // take mins remaining (as seconds) away from total seconds remaining
        return ("0" + (secs - Math.round(mins * 60))).substr(-2);
    }
    </script>
</head>

<body>
    <div id="timer">
        This is only valid for the next
        <input id="minutes" type="text" style="width: 60px; border: none; background-color:none; font-size: 50px; font-weight: bold;"> :
        <input id="seconds" type="text" style="width: 60px; border: none; background-color:none; font-size: 50px; font-weight: bold;">
    </div>
    <script>
    countdown();
    </script>

倒计时
//设定分钟数
var-mins=1;
//计算秒数(不要更改此值!除非时间以不同的速度进行…)
var secs=分钟*60;
函数倒计时(){
setTimeout('Decrement()',1000);
}
函数减量(){
if(document.getElementById){
分钟=document.getElementById(“分钟”);
秒=document.getElementById(“秒”);
//如果剩下不到一分钟
如果(秒<59){
秒。值=秒;
}否则{
minutes.value=getminutes();
seconds.value=getseconds();
}
秒--;
setTimeout('Decrement()',1000);
}
}
函数getminutes(){
//分是秒除以60,四舍五入
分钟=数学楼层(秒/60);
返回(“0”+分钟).substr(-2);
}
函数getseconds(){
//从总剩余秒数中减去剩余分钟数(以秒计)
返回(“0”+(秒-数学四舍五入(分钟*60)).substr(-2);
}
这只对下一个有效
:
倒计时();

这里是:应该为变量分配setTimeout,当secs为0时,清除超时

//设置分钟数
var-mins=1;
//计算秒数(不要更改此值!除非时间以不同的速度进行…)
var secs=分钟*10;
var超时;
函数倒计时(){
超时=设置超时('Decrement()',1000);
}
函数减量(){
if(document.getElementById){
分钟=document.getElementById(“分钟”);
秒=document.getElementById(“秒”);
//如果剩下不到一分钟
如果(秒<59){
秒。值=秒;
}否则{
minutes.value=getminutes();
seconds.value=getseconds();
}
秒--;
如果(秒<0){
clearTimeout(超时);
返回;
}
倒计时();
}
}
函数getminutes(){
//分是秒除以60,四舍五入
分钟=数学楼层(秒/60);
返回(“0”+分钟).substr(-2);
}
函数getseconds(){
//从总剩余秒数中减去剩余分钟数(以秒计)
返回(“0”+(秒-数学四舍五入(分钟*60)).substr(-2);
}
倒计时()
这仅对下一个
:

你似乎没有清除超时,这就是你想要的吗?为什么你认为如果你开始一个新的超时,不管
分钟和
秒的值是多少,那么
减量应该停止?仅供参考:setTimeout不准确,你的计时器结果是错误的。如果我试着让它上升,而不是在00:00被卡住,这有可能吗?任何事情都有可能…(几乎任何事情)