<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#active{
width:20px;
height:20px;
text-align: center;
background-color: #99c1a8;
}
</style>
</head>
<body>
<div id="wrapper"></div>
<div id="active">10</div>
<script>
var _wrapper=document.querySelector("#wrapper");
function test(){
// 两个日期相减
var cha=new Date("2022-12-31 00:00:00")-new Date();
console.log(cha); //119373955毫秒
var days=parseInt(cha/1000/60/60/24); //天
var hours=parseInt(cha/1000/60/60%24); //小时
var minutes=parseInt(cha/1000/60%60); //分钟
var seconds=parseInt(cha/1000%60); //秒
_wrapper.innerHTML=`距离2022-12-31日还有${days}天${hours}时${minutes}分${seconds}秒`
}
setInterval("test()",1000);
var _active=document.querySelector("#active");
var count=_active.innerText;
var id=setInterval(function(){
count--;
//重新写入
_active.innerText=count;
if(count==0){
clearInterval(id);
}
},1000)
</script>
</body>
</html>
08-01
77