0

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <style media="screen">

    </style>
  </head>
  <body>
    <div>Registration closes in <span id="time"><span id='time0'>05</span>:<span id='time1'>00</span>:<span id='time2'>00</span></span> minutes!</div>
    <script type="text/javascript">


function startTimer(duration, display) {
    var timer = duration, hours, minutes, seconds;
    setInterval(function () {
      hours = parseInt(timer / 3600, 10);
        minutes = parseInt(timer / 60, 10);
        seconds = parseInt(timer % 60, 10);
        hours = hours < 10 ? "0" + hours : hours;

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        time0.textContent = hours;
        time1.textContent = minutes;
        time2.textContent = seconds;

        if (--timer < 0) {
            timer = duration;
        }
    }, 1000);
}

window.onload = function () {
    var fiveMinutes = 3600 * 5,
        display = document.querySelector('#time');
    startTimer(fiveMinutes, display);
};
    </script>
</body>
</html>

Как сделать так, чтобы это чудо заработало?

1
  • 1
    Починить можно с помощью console.log
    – user256824
    14 авг 2019 в 5:30

1 ответ 1

0

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <style media="screen">

    </style>
  </head>
  <body>
    <div>Registration closes in <span id="time"><span id='time0'>05</span>:<span id='time1'>00</span>:<span id='time2'>00</span></span> minutes!</div>
    <script type="text/javascript">


function startTimer(secs, display) {
    var seconds = secs, date;
    setInterval(function () {
        date = new Date(seconds*1000);
        time0.textContent = ("0" + date.getUTCHours()).slice(-2);
        time1.textContent = ("0" + date.getMinutes()).slice(-2);
        time2.textContent = ("0" + date.getSeconds()).slice(-2);

        if (--seconds < 0) {
            seconds = secs;
        }
    }, 1000);
}

window.onload = function () {
    var fiveMinutes = 300,
        display = document.querySelector('#time');
    startTimer(fiveMinutes, display);
};
    </script>
</body>
</html>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.