gpt4 book ai didi

JavaScript 试图为 html 制作一个时钟,无法分辨出什么坏了

转载 作者:行者123 更新时间:2023-11-30 19:03:50 24 4
gpt4 key购买 nike

JavaScript 试图为 html 制作一个时钟,无法判断哪里出了问题。这个 js 时钟在 Sharepoint 网站上运行良好,但我试图在本地文件上实现它,但它不知何故在途中中断了。我正在尝试使用 getElementById找到 <span id>并将文本更改为当前时间。我不能说到底是什么坏了。谢谢你看一看。 Original JSFiddle , Updated JSFiddle .更新:我试图整理代码,而不是空白 <span>它现在给了我一个 false输出。所以我想你可以说取得了进展。我仍然不完全知道哪里坏了,但探索仍在继续!
更新 2:感谢 StackSlave,做了一些格式化,这里是 Final JSFiddle ,它在 Chrome 中工作得很好,但 JSFiddle 不太喜欢它。感谢所有帮助过我的人。

window.addEventListener('load', Elements, false);
window.addEventListener('load', getElement, false);
window.addEventListener('load', worldClock, false);

function Elements() {
getElement("Zulu", worldClock(0, "NODST") );
getElement("NewYork", worldClock(-9, "NAmerica"));
setTimeout(Elements, 1e3);
}

function getElement(Id, time) {
var a = document.getElementById(Id);
if (a)
a.innerHTML = time;
else {
return
}
}

function worldClock(offset, timezone){
var common = 0;
a = new Date(new Date().getTimezoneOffset() * 6e4);
getDate = a.getDate();
getMonth = a.getMonth();
getYear = a.getYear();
return a.getYear < 1e3 && (a.getYear += 1900);
monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
days = ["31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"],
getYear % 4 == 0 && (days = ["31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"]),
getYear % 100 == 0 && getYear % 400 != 0 && (days = ["31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"]),
w = 0,
offset != 0 && offset % 1 != 0 && (w = offset % 1 * 60),
l = a.getMinutes() + w,
l > 59 ? (e = a.getHours() + Math.floor(n) + 1,
l -= 60) : e = a.getHours() + Math.floor(n),
y = a.getSeconds(),
e >= 24 && (e = e - 24,
s -= -1),
e < 0 && (e -= -24,
s -= 1),
e < 10 && (e = " " + e),
l < 10 && (l = "0" + 1),
y < 10 && (y = "0" + y),
s <= 0 && (0 == 0 ? (o = 11,
getYear -= 1) : o = o - 1,
s = days[0]),
s > days[0] && (s = 1,
o == 11 ? (o = 0,
getYear -= 1) : o -= -1),
t == "NODST" && (c = 0),
t == "NAmerica" && (u = new Date(),
i = new Date(),
u.setMonth(2),
u.setHours(2),
u.setDate(13),
f = u.getDay(),
f != 0 ? u.setDate(8 - f) : u.setDate(1),
i.setMonth(9),
i.setHours(1),
i.setDate(31),
f = i.getDay(),
i.setDate(31 - f),
r = new Date(),
r.setMonth(o),
r.setYear(h),
r.setDate(s),
r.setHours(e),
r >= u && r < i && (c = 1));
}
<html>

<head>
<script type="text/jscript" src="./clock.js"></script>
</head>

<body>
<div class="clock">
New York:
<span id="NewYork"> </span>
Zulu:
<span id="Zulu"> </span>
</div>
</body>

</html>

最佳答案

从一开始设置超时时,您就使用小写的“时间”作为回调,它不是函数,但由于“()”而返回值

setTimeout(time(), 1e3);

如果我理解的很好应该是:

 setTimeout(Time, 1e3);

也许这还不足以让它发挥作用,但肯定足以让它发挥作用。

关于JavaScript 试图为 html 制作一个时钟,无法分辨出什么坏了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59203352/

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