以下是一份可供修改的元旦倒计时HTML代码及其使用教程:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>元旦倒计时</title>
<style type="text/css">
#countdown {
font-size: 50px;
color: red;
text-align: center;
margin-top: 20%;
}
</style>
</head>
<body>
<div id="countdown"></div>
<script type="text/javascript">
var endtime = new Date("January 1, 2024 00:00:00");
var now = new Date();
function countdown() {
var leftTime = endtime - now;
if (leftTime < 0) {
document.getElementById("countdown").innerHTML = "倒计时结束";
return;
}
var days = parseInt(leftTime / 1000 / 60 / 60 / 24);
var hours = parseInt(leftTime / 1000 / 60 / 60 % 24);
var minutes = parseInt(leftTime / 1000 / 60 % 60);
var seconds = parseInt(leftTime / 1000 % 60);
document.getElementById("countdown").innerHTML = "距离元旦还有 " + days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒";
now = new Date();
setTimeout(countdown, 1000);
}
countdown();
</script>
</body>
</html>
暂无评论