实时动态时间显示 - 简洁 JavaScript 代码示例
<!DOCTYPE html>
<html>
<head>
<title>实时动态时间显示</title>
<script>
function updateTime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeString = hours + ":" + minutes + ":" + seconds;
document.getElementById('time').innerHTML = timeString;
}
<pre><code> window.onload = function() {
updateTime();
setInterval(updateTime, 1000);
};
</script>
</code></pre>
</head>
<body>
<div id='time'></div>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/nVof 著作权归作者所有。请勿转载和采集!