0

我不明白为什么检查器未定义(因此不满足条件 ===0 或 ==1)。

它似乎可以在 JS Fiddle 中工作,但没有准备好的功能,但它不适用于实时系统。

var checker = 0;
$(window).ready(function () {



function wertelesen() {



    alert(checker);

    if ($("#ersterstatus").html() == '1') {
        if (checker === 0) {
            alert(checker);
            var currentTime = new Date();
            var hours = currentTime.getHours();
            var minutes = currentTime.getMinutes();
            var seconds = currentTime.getSeconds();

            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (seconds < 10) {
                seconds = "0" + seconds;
            }

            $("#status1time").html(hours + ":" + minutes + ":" + seconds);
            var checker = 1;
        }

        $("#sd1").html('<img src="img/Status01.png" alt="Status aktiv" class="statusleuchte">');
    }

    if ($("#ersterstatus").html() == '0') {
        if (checker === 1) {
            alert(checker);
            var currentTime = new Date();
            var hours = currentTime.getHours();
            var minutes = currentTime.getMinutes();
            var seconds = currentTime.getSeconds();

            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (seconds < 10) {
                seconds = "0" + seconds;
            }

            $("#status1time").html(hours + ":" + minutes + ":" + seconds);
            var checker = 0;
        }

        $("#sd1").html('<img src="img/Status00.png" alt="Status inaktiv" class="statusleuchte">');
    }

    setTimeout(wertelesen, 1000);
}
setTimeout(wertelesen, 1000);

});

</script>
4

1 回答 1

2

您正在从全局范围重新声明checker到本地范围:

$("#status1time").html(hours + ":" + minutes + ":" + seconds);
var checker = 1;

只需将其更改为:

$("#status1time").html(hours + ":" + minutes + ":" + seconds);
checker = 1;

正如所指出的,你也这样做了两次:

$("#status1time").html(hours + ":" + minutes + ":" + seconds);
var checker = 0;
于 2013-07-24T07:13:15.663 回答