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