簡體   English   中英

為什么var checker未定義?

[英]Why is the var checker undefined?

我不明白為什么檢查器是未定義的(因此不滿足條件=== 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>

您正在從全局范圍到本地范圍重新聲明checker

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

只需將其更改為:

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

正如所指出的那樣,你也是這樣做了兩次:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM