简体   繁体   English

计时器为零时如何显示div?

[英]How do I display a div when my timer hits zero?

here's my code: 这是我的代码:

$('#TESTER').hide();  
$('#titlehead2').click(
    function() {
        var doUpdate = function() {
            $('.countdown').each(function() {
                var count = parseInt($(this).html());
                if (count !== 0) {
                    $(this).html(count - 1);
                }
            });
        };
        setInterval(doUpdate,1000);
        if(count <= 0) $('#TESTER').show();
    }
);

#TESTER is the div I want to display when the timer reaches zero, and #titlehead2 is my play button for the timer. #TESTER是计时器要为零时要显示的div,而#titlehead2是计时器的播放按钮。 Any help will be much appreciated. 任何帮助都感激不尽。

You need to check the value of counter within the timer 您需要在计时器内检查counter的值

$('#TESTER').hide();
$('#titlehead2').click(function () {
    var doUpdate = function () {
        //need to look whether the looping is needed, if there are more than 1 countdown element then the timer logic need to be revisted
        $('.countdown').each(function () {
            var count = parseInt($(this).html());
            if (count !== 0) {
                $(this).html(count - 1);
            } else {
                $('#TESTER').show();
                //you also may want to stop the timer once it reaches 0
                clearInterval(timer);
            }
        });
    };
    var timer = setInterval(doUpdate, 1000);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我的计时器为零时呼叫div容器 - Call a div-container when my timer reaches zero 如何在 html div 的代码中显示 javascript 计时器? - How do I show the javascript timer in my code in an html div? 当特定div命中或距顶部100像素时,我如何才能使固定标头滚动走 - How can i make my fixed header scroll away when a specific div hits it, or when it is 100px from the top 为什么我的if函数不针对“timer”变量? 当计时器达到0时,我试图让它提醒/控制台“时间到了” - Why isn't my if function targeting the “timer” variable? I am trying to get it to alert/console “time is up” when the timer hits 0 当计时器到达 00:00 时,如何设置 5 秒的延迟? - How can I set a delay of 5 seconds when the timer hits 00:00? 当计时器分钟达到某个目标时,我如何更改页面的背景颜色? - How am i able to change the background color of the page when the timer minutes hits at a certain target? 当我的计时器达到零时调用一个函数 - Call a function when my timer reaches zero 当div到达页面顶部时如何记录 - How to log when a div hits the top of the page 如何让我的应用程序显示计时器并让用户输入自己的输入? - How do I make my app display a timer and let the user type their own inputs? 我如何显示 <div> 网址中包含ID的时间? - How do I display a <div> when the URL contains the ID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM