用jQuery书写一个倒计时程序
时间: 2023-09-13 13:05:09 浏览: 40
可以参考以下代码实现:
```html
<!DOCTYPE html>
<html>
<head>
<title>倒计时程序</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="countdown"></div>
<script>
$(document).ready(function() {
var countDownDate = new Date("Jan 1, 2022 00:00:00").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
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);
$("#countdown").html(days + "d " + hours + "h " + minutes + "m " + seconds + "s ");
if (distance < 0) {
clearInterval(x);
$("#countdown").html("EXPIRED");
}
}, 1000);
});
</script>
</body>
</html>
```
该代码会在网页上显示一个倒计时,倒计时结束时会显示 "EXPIRED"。你可以根据需要修改倒计时的时间和显示方式。