0

我的计时器有问题-

var myTimer = function () {
    var d = Date.now();
    // var t=d.toLocaleTimeString();
    var timerSeconds = Math.round((od - d) / 1000);
    document.getElementById("timer").innerHTML = "Time left for this tour:" + timerSeconds;
    if (timerSeconds > 0) {
        setTimeout(arguments.callee, 1000);
    } else {
        finTour();
    }
};
myTimer();

它调用这个函数:

var finTour = function () {
    deleteCartes();
    randomCell();
    od = Date.now() + 5000;
    myTimer();
    window.setTimeout(function () {
        tourOfComp();
    }, 5000)

    var tourOfComp = function () {

        for (var i = 0; i < 12; i++) {
            if (document.getElementsByTagName("td")[i].style.backgroundColor == "aqua") {
                document.getElementsByTagName("td")[i].firstChild.data = cartes[prochaineCarte++]
            }
        }
        for (var j = 0; j < 12; j++) {
            if (document.getElementsByTagName("td")[j].style.backgroundColor == "aqua")
                document.getElementsByTagName("td")[j].style.backgroundColor = "";
        }
        for (var k = 0; k < 3; k++) {
            tab[k].value = "";
        }
        od = Date.now() + timeFixe;
        myTimer();
    };

问题是当我修复时间 20 时,它会调用这两个最后一个函数,时间总是 5 而从不 20 似乎它不会更新时间,而只是重复这个:

window.setTimeout(function ()
{
 tourOfComp();
},5000)
4

0 回答 0