gpt4 book ai didi

javascript - 为什么 var 检查器未定义?

转载 作者:行者123 更新时间:2023-12-02 18:30:44 25 4
gpt4 key购买 nike

我不明白为什么 checker 未定义(因此不满足条件 ===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;

关于javascript - 为什么 var 检查器未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17827404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com