You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript倒计时器到期后未更新显示的问题求助

JavaScript倒计时器到期后未更新显示的问题求助

我遇到了一个JavaScript倒计时器的问题:当设定的时间结束后,页面并没有切换到我准备好的提示信息,而是继续显示负数的倒计时数值。我实在搞不懂哪里出问题了,希望能得到大家的帮助!

以下是我的完整代码:

HTML部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2 id="Bucharest"></h2>
</body>
</html>

CSS部分

body {
    text-align: center;
    font-size: xx-large;
    font-weight: bold;
    font-family: "Gill Sans", sans-serif;
}

JavaScript部分

var Bucharest = new Date("April 26, 2023 13:50:00").getTime();

var Bucharestinterval = setInterval(function() {

    var Bucharestnow = new Date().getTime();
    var Bucharestdistance = Bucharest - Bucharestnow;

    var Bucharestdays = Math.floor(Bucharestdistance / (1000 * 60 * 60 * 24));
    var Bucharesthours = Math.floor(
        (Bucharestdistance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
    );
    var Bucharestminutes = Math.floor(
        (Bucharestdistance % (1000 * 60 * 60)) / (1000 * 60)
    );
    var Bucharestseconds = Math.floor((Bucharestdistance % (1000 * 60)) / 1000);

    document.getElementById("Bucharest").innerHTML =
        Bucharestdays + "d " + Bucharesthours + "h " + Bucharestminutes + "m " + Bucharestseconds + "s ";

    if (Bucharestinterval < 0) {
        clearInterval(Bucharestinterval);
        document.getElementById("Bucharest").innerHTML = "Let's go Bucharest!!!";
    }
}, 1);

我的预期是当倒计时结束后,定时器会被清除,页面显示“Let's go Bucharest!!!”,但实际情况完全不是这样。有没有人能帮我找出问题所在?

备注:内容来源于stack exchange,提问作者samirkiki542

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 15:34:52