Countdown timer-php+mysql+js

前端 未结 4 1406
忘掉有多难
忘掉有多难 2021-01-27 17:22

I am working on online examination. In which the examination duration will fetch by mysql(in minutes). I want to show the countdown time on the top of the page.

current

4条回答
  •  别那么骄傲
    2021-01-27 17:39

    Before running the test you need to calculate exact test end time on the server side and save it into session:

    
    

    Then, if you provide it to your client-side script from HTML:

    Time left:
    
    

    Add this code into your jQuery DOM-ready handler to start all timers on a page:

    $('.timer').each(function() {
        var target = new Date($(this).data('end')), update, $this = $(this);
        (update = function () {
            var now = new Date();
            $this.text((new Date(target - now)).toUTCString().split(' ')[4]);
            if (Math.floor((target - now)/1000) == 0) return; // timer stops
            setTimeout(update, 1000);
        })();
    });
    

提交回复
热议问题