<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>倒计时</title>
</head>
<body>
<div id="box">
<span>00天</span>
<span>00时</span>
<span>00分</span>
<span>00秒</span>
</div>
<script>
var box = document.getElementById('box');
var times = box.getElementsByTagName('span');
function time(){
var EndTime = new Date('2017/04/26 00:00:00');
var NowTime = new Date();
var t = EndTime.getTime() - NowTime.getTime();
var d = 0;
var h = 0;
var m = 0;
var s = 0;
if(t >= 0){
d = parseInt(t/1000/60/60/24);
h = parseInt(t/1000/60/60%24);
m = parseInt(t/1000/60%60);
s = parseInt(t/1000%60);
}
times[0].innerHTML = d + '天';
times[1].innerHTML = h + '时';
times[2].innerHTML = m + '分';
times[3].innerHTML = s + '秒';
}
setInterval(time,1000);
</script>
</body>
</html>
JS实现倒计时
最新推荐文章于 2024-05-02 16:46:30 发布