因为一个竞拍项目需要用到倒计时,找了一下之前的代码,重新处理一下使用setInterval
来实现倒计时赋值。
1.效果图
效果截图
2.HTML源码
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简易倒计时</title>
</head>
<body>
<div id="CountMsg" class="row-left">
<span id="t_day">00天</span>
<span id="t_hour">00时</span>
<span id="t_minute">00分</span>
<span id="t_second">00秒</span>
</div>
</body>
</html>
<script type="text/javascript">
function countdownTime(){
//截止时间
var endte = '2021/3/18 03:20:00'
var endtime= new Date(endte)
var nowtime = new Date()
var t =endtime.getTime() - nowtime.getTime()
var d=Math.floor(t/1000/60/60/24)
if(d<=0) { d=00}
var h=Math.floor(t/1000/60/60$)
if(h<=0) { h=00}
var m=Math.floor(t/1000/60`)
if(m<=0) { m=00}
var s=Math.floor(t/1000`)
if(s<=0) { s=00}
document.getElementById("t_day").innerHTML = d "天"
document.getElementById("t_hour").innerHTML = h "时"
document.getElementById("t_minute").innerHTML = m "分"
document.getElementById("t_second").innerHTML = s "秒"
}
//赋值倒计时
setInterval(countdownTime,1000)
</script>