要實現(xiàn)一個在線時間顯示全屏網(wǎng)頁,可以使用HTML、CSS和JavaScript。以下是一個簡單的示例:
- 創(chuàng)建一個HTML文件,例如
index.html
,并添加以下內(nèi)容:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>在線時間顯示全屏</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
#time {
font-size: 48px;
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div id="time">當(dāng)前時間:2022-09-25 16:45:00</div>
<script>
function updateTime() {
const date = new Date();
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0');
const ampm = date.getHours() >= 12 ? 'PM' : 'AM';
return `${hours}:${minutes}:${seconds} ${ampm}`;
}
function updateTimeDisplay() {
const timeElement = document.getElementById('time');
timeElement.textContent = updateTime();
}
setInterval(updateTimeDisplay, 1000);
</script>
</body>
</html>
- 在瀏覽器中打開
index.html
文件,你將看到一個全屏的在線時間顯示。這個示例使用了JavaScript的setInterval
函數(shù)每秒更新一次時間顯示,并使用document.getElementById
獲取HTML元素。
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。