我想使用 D3.js 来显示我正在做的即将到来的项目的运行时间。它在localhost上工作得很好,但我的 JSFiddle - 它不会自动更新。我如何为 JSFiddle 设置东西有问题吗?
我为 jQuery & D3js 添加了外部资源。当我检查元素时,JSFiddle 中结果的源代码看起来与localhost中的相同
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);
};