js实现倒计时
新年倒计时 :<span class="time"></span>
<script>
var time = document.querySelector (".time");
window.onload = function () {
var future = new Date("2021-01-01");
var futureTime = future.getTime();
var timer = setInterval(function () {
var today = new Date();
var todayTime = today.getTime();
var cha = futureTime - todayTime;
var sec = parseInt(cha / 1000 % 60);
var min = parseInt(cha / 1000 / 60 % 60);
var hour = parseInt(cha / 1000 / 60 / 60 % 24);
var date = parseInt(cha / 1000 / 60 / 60 / 24 % 30);
var mon = parseInt(cha / 1000 / 60 / 60 / 24 / 30 % 12);
time.innerHTML = `${mon}月${date}天${hour}小时${min}分${sec}秒元旦`;
},1000)
}
</script>