js倒计时的实现代码(三款js倒计时代码)

发布时间:2021-01-20编辑:脚本学堂
为大家提供三个js实现的倒计时代码,都比较简单,适合初学的朋友参考。当然也可以应用在一些要求不高的网页上。

1、js倒计时代码一

<script language="javascript" type="text/javascript">  
function djs(){  
var urodz= new date("11/12/2008");   
var now = new date();  
var num  
var ile = urodz.gettime() - now.gettime();    
var dni = math.floor(ile / (1000 * 60 * 60 * 24));    
if (dni >1)    
num=dni+1
else if (dni == 1) num=2   
else if (dni == 0) num=1
else num=0   
document.write(num)    
}  
</script>

2、js倒计时代码二

<script language="javascript">   
<!-- begin   
  var timedate= new date("january 14,2016");   
  var times="研究生考试";   
  var now = new date();   
  var date = timedate.gettime() - now.gettime();   
  var time = math.floor(date / (1000 * 60 * 60 * 24));   
  if (time >= 0) ;  
    document.write("<li><font color=#dedbde>现在离2016年"+times+"还有: <font color=#ffffff><b>"+
    time +"</b></font> 天</font></li>");  
// end -->  
</script>

3、js倒计时代码三

<script language="javascript" type="text/javascript">
var interval = 1000;
function showcountdown(year, month, day, divname) {
var now = new date();
var enddate = new date(year, month - 1, day, 14, 07);
var lefttime = enddate.gettime() - now.gettime();
var leftsecond = parseint(lefttime / 1000);
var day1 = math.floor(leftsecond / (60 * 60 * 24));
var hour1 = math.floor((leftsecond - day1 * 24 * 60 * 60) / 3600);
var hour = math.floor((leftsecond - 60 * 60) / 3600);
//如果小时为负数 显示0
if (hour > 0) {
}
else {
hour = 0;
}
if (day1 < 0) {
hour = hour1
}
var minute = math.floor((leftsecond - day1 * 24 * 60 * 60 - hour1 * 3600) / 60);
var second = math.floor(leftsecond - day1 * 24 * 60 * 60 - hour1 * 3600 - minute * 60);
var cc = document.getelementbyid(divname);
//如果结束时间为负数 就显示0
if (lefttime > 0) {
cc.innerhtml = hour + "小时" + minute + "分" + second + "秒";
//如果显示年份 取消注释
//cc.innerhtml = "距离" + year + "年" + month + "月" + day + "日还有:" + hour + "小时" + minute + "分" + second + "秒";
}
else {
cc.innerhtml = 0 + "小时" + 0 + "分" + 0 + "秒";
}
}
//show_date是div的id 2015,8,10表示是年月日的意思 参数根据自己的需求设置。
window.setinterval(function () { showcountdown(2015, 8, 10, 'show_date'); }, interval);
</script>

倒计时在以下容量中显示:

<div id="show_date"></div>