活动倒计时范例(日期倒计时例子)

本文提供了一个简单的HTML页面示例,使用JavaScript实现了一个倒计时功能,该功能针对特定日期进行倒计时,并在时间结束后显示提示信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 活动倒计时范例(日期倒计时例子)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>倒计时</title>
</head>

<body>
<p id="demo"></p>
<script>
// 设置咱们准备倒计时的日期
const countDownDate = new Date("2021-11-30 24:00:00").getTime();
// 每秒更新一次
var x = setInterval(function() {
// 获取当前时间
var now = new Date().getTime();
// 获取当前时间与countDownDate 的时间差
var distance = countDownDate - now;
// 将时间差转为 days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("demo").innerHTML = days + "天 " + hours + ":"
+ minutes + ":" + seconds + "";
// 若是时间差耗尽,结束定时器,秒杀结束
if (distance < 0) {
     clearInterval(x);
     document.getElementById("demo").innerHTML = "提示:活动已经结束。";
  }
}, 1000);
  </script>
</body>

</html>

//来源:http://cn.voidcc.com/question/p-mjepyoil-hk.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值