Javascript 未捕获类型错误:无法设置属性';文本内容';Laravel内倒计时计时器中的空值

Javascript 未捕获类型错误:无法设置属性';文本内容';Laravel内倒计时计时器中的空值,javascript,php,laravel,Javascript,Php,Laravel,我正在用javascript为php/laravel应用程序运行计时器。在控制台中,当计时器运行时,我每秒都会收到一个运行错误。我不知道如何消除这个错误。它不会影响应用程序的操作,因为计时器会工作。我还尝试将代码包装到DOMContentLoaded函数中,但没有效果。有人能告诉我我错过了什么吗。非常感谢。 以下是js代码: document.addEventListener("DOMContentLoaded", function() { function sta

我正在用javascript为php/laravel应用程序运行计时器。在控制台中,当计时器运行时,我每秒都会收到一个运行错误。我不知道如何消除这个错误。它不会影响应用程序的操作,因为计时器会工作。我还尝试将代码包装到DOMContentLoaded函数中,但没有效果。有人能告诉我我错过了什么吗。非常感谢。 以下是js代码:

document.addEventListener("DOMContentLoaded", function() {

    function startTimer(duration, display) {
        let timer = duration, minutes, seconds;
        setInterval(function () {
            minutes = parseInt(timer / 60, 10);
            seconds = parseInt(timer % 60, 10);

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

            display.textContent = minutes + ":" + seconds;

            if (--timer < 0) {
                timer = duration;
                alert('Your time has expired');
                window.location.href="/student/exam";
            }
        }, 1000);
    }

    window.onload = function () {
        let sixtyMinutes = 60 * 60,
            display = document.querySelector('#time');
        startTimer(sixtyMinutes, display);
    };
});
再次感谢您的帮助。多谢各位

编辑::错误图像:

在Firefox中,我遇到以下错误:

Uncaught TypeError: display is null
    startTimer http://lionsfieldtest.test/assets/js/custom.js:94
custom.js:94:13

您发布的代码运行良好-如果您不相信,请将其制作成代码段谢谢Jaromanda X。是的,我相信代码也运行良好,但如何在控制台中消除错误?或者我只是接受每一秒的错误。我以前从未在应用程序中尝试过运行计时器。您误解了-代码没有输出任何错误
display.textContent = minutes + ":" + seconds;
Uncaught TypeError: display is null
    startTimer http://lionsfieldtest.test/assets/js/custom.js:94
custom.js:94:13