听得入迷

听得入迷

愿世界安康,愿你我皆好!
  • 分类数量4
  • 标签数量12
  • 文章数量112
  • 评论数量4
2021-03-26

添加倒计时

#技术

添加倒计时

之前有过网站正计时,现在有了倒计时。这次的倒计时是从Tiger_Root博客要来的,进行了简化小改。

倒计时.webp

<div style="text-align:center; padding:2em 1em 1em 1em;color:#fff;background:#353A40;border-radius:1em;">
<font style="font-size:1.5em;">考研倒计时</font>
<div id="CountMsg" class="HotDate" style="margin:0;">
<span id="t_d" class="time"> 天</span>
<span id="t_h" class="time"> 时</span>
<span id="t_m" class="time"> 分</span>
<span id="t_s" class="time"> 秒</span>
</div>
</div>
<script type="text/javascript">  
function getRTime() {      
var EndTime = new Date('2021/12/25 08:00:00');//目标时间     
var NowTime = new Date();     
var t = EndTime.getTime() - NowTime.getTime();            
var d = Math.floor(t / 1000 / 60 / 60 / 24); 
var h = Math.floor(t / 1000 / 60 / 60 % 24);         
var m = Math.floor(t / 1000 / 60 % 60);              
var s = Math.floor(t / 1000 % 60);    
var day = document.getElementById("t_d");   
if (day != null) {       
day.innerHTML = d + " 天";      
}   
var hour = document.getElementById("t_h");   
if (hour != null) {       
hour.innerHTML = h + " 时";     
}   
var min = document.getElementById("t_m");   
if (min != null) {       
min.innerHTML = m + " 分";      
}   
var sec = document.getElementById("t_s");   
if (sec != null) {       
sec.innerHTML = s + " 秒";   
} 
}    
setInterval(getRTime, 1000);    
</script> 

Comments