我正在尝试创建一个显示2个国家/地区时间的时钟。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script>
function disptime() {
now = new Date()
hours = now.getHours();
hours = hours < 10 ? "0" + hours:hours;
minutes = now.getMinutes();
minutes = minutes < 10 ? "0" + minutes:minutes;
seconds = now.getSeconds();
seconds = seconds < 10 ? "0" + seconds:seconds;
milli = now.getTime();
millib = milli + (6*60*60*1000);
bhutan = new Date();
bhutan = setTime(millib);
bhutanHours = bhutan.getHours();
bhutanHours = bhutanHours < 10 ? "0" + bhutanHours:bhutanHours;
document.getElementById("bhutanClock").innerHTML=bhutanHours+ " : " + minutes + " : " + seconds;
document.getElementById("UKClock").innerHTML=hours+ " : " + minutes + " : " + seconds;
setTimeout("disptime()",1000);
}
</script>
</head>
<body onload="disptime()">
<p id="bhutanClock"></p>
<p id="UKClock"></p>
</body>
</html>
加载此页面时,为什么浏览器中看不到任何内容?
最佳答案
问题出在bhutan = setTime(millib);
函数setTime
不在全局范围内定义。我相信您正在寻找bhutan.setTime(millib)
代替。
此外,应将setTimeout替换为setTimeout(disptime, 1000);
。
工作fiddle。
关于javascript - JavaScript Clock问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34374260/