显示运行时间

Display running time

本文关键字:运行时间 显示      更新时间:2023-09-26

我想使用D3.js来显示我正在做的即将到来的项目的运行时间。它在localhost上工作得很好,但是我的JSFiddle -它不会自动更新。我如何为JSFiddle设置东西有问题吗?

我为jQuery添加了外部资源&D3js。当我检查元素时,JSFiddle中结果的源代码看起来与localhost

中的源代码相同

jstimeout .

var d, h, m, s, DayNight;
currtime();
$(document).ready(function () {
    setInterval("currtime()", 1000);
});
d3.select("#runtime")
    .append("text")
    .text("Current time: ")
    .append("span")
    .attr("id", "time")
    .text(h + ":" + m + ":" + s + " " + DayNight);
function currtime() {
    d = new Date();
    h = d.getHours();
    m = d.getMinutes();
    s = d.getSeconds();
    DayNight = "PM";
    if (h>12) h=h-12;
    if (h < 12) DayNight = "AM";
    if (m <= 9) m = "0" + m;
    if (s <= 9) s = "0" + s;
    d3.select("#runtime")
        .select("#time")
        .text(h + ":" + m + ":" + s + " " + DayNight);
};

查看JavaScript控制台,您可以看到正在发生的事情。currtime() is not defined也eval是邪恶的(即使在setInterval()内部)。这是一个更新的小提琴工作。改变这个:

$(document).ready(function () {
    setInterval("currtime()", 1000);
});

:

$(document).ready(function () {
    setInterval(currtime, 1000);
});