直接撸代码:
<div class="time">
<span id="showTime"></span>
</div>
<script>
function countDown(time,id){
var startTime = new Date();
var endTime = new Date(time);
var distance = endTime.getTime() - startTime.getTime();
var day = 0;
var hour = 0;
var minute = 0;
var second =0;
if(distance>=0){
day = Math.floor(distance/1000/60/60/24);
hour = Math.floor(distance/1000/60/60%24);
minute = Math.floor(distance/1000/60%60);
second = Math.floor(distance/1000%60);
}else{
alert("倒计时活动已结束");
}
document.getElementById(id).innerHTML = day + "天" + hour + "时" + minute + "分" + second + "秒";
}
// countDown('2019/07/25 19:15:00','showInterval');
setInterval(function(){countDown('2019/07/26 12:00:00','showTime');},0);
<script>