xxxxxxxxxx
<!DOCTYPE html>
<html>
<title>JavaScript setInterval()示例 - 基础教程(div.cn)</title>
<head>
<style>
#result {
display: flex;
justify-content: center;
color: #ec181e;
font-size: 25vw;
font-weight: 900;
text-shadow: 0 6px 4px rgba(255, 100, 100, 0.6);
}
</style>
</head>
<body>
<div id="result">00:00:00</div>
<script>
// 每1秒执行一次startTimer()
setInterval(startTimer, 1000);
function startTimer() {
var date = new Date();
document.getElementById("result").innerHTML = date.toLocaleTimeString();
}
</script>
</body>
</html>