秒杀倒计时
<style>.clock {
width: 300px;
height: 30px;
border: 1px solid #000;
}
</style>
</head>
<body>
<div class=&#34;clock&#34;></div>
<script>
var clock = document.querySelector(&#34;.clock&#34;);
//倒计时结束时间是: 2023/3/24 8:00结束
// 剩几小时几分钟几秒
// 25h--- d = 1天 h = 1小时
function countdown() {
var startTime = new Date().getTime();
var endTime = new Date(&#34;2023/3/25 17:00:00&#34;).getTime();
var interval = (endTime - startTime) / 1000; // 秒
var d = parseInt(interval / 60 / 60 / 24)
var h = parseInt(interval / 60 / 60 % 24);
var m = parseInt(interval / 60% 60)
var s = parseInt(interval % 60) // 剩余时间是85s , 秒位应该显示25
if (h < 10) h = &#39;0&#39; + h
if (m < 10) m = &#39;0&#39; + m
if (s < 10) s = &#39;0&#39; + s
clock.innerText = &#39;剩余&#39; + d + &#39;天 &#39; + h + &#34;:&#34; + m + &#34;:&#34; + s
}
countdown();
setInterval(countdown,1000)
</script>
</body>
运行结果
-----------------------------
页:
[1]