请写一个长宽为150px的div并用Js改变里面的内容为当前时间每一秒更新一次
以下是使用JavaScript实现的代码:
HTML:
<div id="time" style="width: 150px; height: 150px;"></div>
JavaScript:
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;
}
setInterval(updateTime, 1000);
这个代码会在页面上创建一个150px * 150px的div,并且使用JavaScript每秒更新一次div中的文本内容,以显示当前时间。
原文地址: https://www.cveoy.top/t/topic/eFig 著作权归作者所有。请勿转载和采集!