【发布时间】:2023-03-19 18:12:01
【问题描述】:
我一直试图让我的页面在午夜刷新,但我编写的代码不起作用。
这是我写的代码:
function reloadClock() {
var reloadTime = new Date();
var hrs = reloadTime.getHours();
var min = reloadTime.getMinutes();
var sec = reloadTime.getSeconds();
// I tried this code, it will not work.
if (hrs == 0 && min == 0 && sec == 0) {
alert('this page will now reload');
location.reload();
}
// I also tried this code, still can't get it to work.
if (hrs == 14) { // Works as intended.
alert(hrs);
if (min == 31) { // Works as intended.
alert(min);
if (sec == 0) { // Does not work as intended.
alert(sec);
location.reload();
}
}
}
setTimeout(reloadClock(), 1000);
}
有人知道解决办法吗?
【问题讨论】:
-
setTimeout(reloadClock(), 1000);也不起作用
标签: javascript clock