1分钟30秒倒数计时器javascript

时间:2018-09-28 02:51:07

标签: javascript countdowntimer

我有代码,但是需要2分钟的计时器,我需要将其修改为1分钟30秒的计时器。

我已经尝试过,但是无法从1:30开始计时。

我是这一行的初学者,想学习如何做。

这是代码

[^:]+

3 个答案:

答案 0 :(得分:0)

我将使用以下内容:

<div id=timer></div>
<script type="text/javascript">

    var maxTicks = 90;
    var tickCount = 0;

    var tick = function()
    {
        if (tickCount >= maxTicks)
        {
            // Stops the interval.
            clearInterval(myInterval);
            return;
        }

        /* The particular code you want to excute on each tick */
        document.getElementById("timer").innerHtml = (maxTicks - tickCount);

        tickCount++;
    };

    // Start calling tick function every 1 second.
    var myInterval = setInterval(tick, 1000);

</script>

答案 1 :(得分:0)

<div id=timer></div>
<script type="text/javascript">
    var timeoutHandle;
    function countdown(minutes, seconds) {
        function tick() {
            var counter = document.getElementById("timer");
            counter.innerHTML =
                minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
            seconds--;
            if (seconds >= 0) {
                timeoutHandle = setTimeout(tick, 1000);
            } else {
                if (minutes >= 1) {
                    // countdown(mins-1);   never reach “00″ issue solved:Contributed by Victor Streithorst
                    setTimeout(function () {
                        countdown(minutes - 1, 59);
                    }, 1000);
                }
            }
        }
        tick();
    }

    countdown(1, 30);
</script>

答案 2 :(得分:0)

详细选项https://www.growthsnippets.com/30-second-countdown-timer-javascript/

var remainingTime = 30;
    var elem = document.getElementById('countdown_div');
    var timer = setInterval(countdown, 1000); //set the countdown to every second
    function countdown() {
      if (remainingTime == -1) {
        clearTimeout(timer);
        doSomething();
      } else {
        elem.innerHTML = remainingTime + ' left';
        remainingTime--; //we subtract the second each iteration
      }
    }