<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>倒计时</title>
<script type="text/javascript" src="times.js"></script>
</head>
<div class="w"></div>
<body>

<div>设置倒计时的结束年月日和时间</div>
<div>指定两个时间之间的倒计时</div>
<select id="year"></select>
<!--连接符 -->
<span>-</span>
<!--连接符 -->
<select id="month"></select>
<!--连接符 -->
<span>-</span>
<!--连接符 -->
<select id="date"></select>
<!--连接符 -->
 
<!--连接符 -->
<select id="h"></select>
<span>:</span>
<select id="m"></select>
<span>:</span>
<select id="s"></select>
  <div style="margin:10px 0;"></div>
<select id="year1"></select>
<!--连接符 -->
<span>-</span>
<!--连接符 -->
<select id="month1"></select>
<!--连接符 -->
<span>-</span>
<!--连接符 -->
<select id="date1"></select>
<!--连接符 -->
 
<!--连接符 -->
<select id="h1"></select>
<span>:</span>
<select id="m1"></select>
<span>:</span>
<select id="s1"></select>
<div style="margin:10px 0;"></div>
<input type="button" value="提交" id="but" />
<div style="margin:10px 0;"></div>
<div>距离秒杀开始还有:<span id="tt1">还未开启秒杀</span></div>
<div>距离秒杀结束还有:<span id="tt">已结束</span></div>
<!--<dl>
	<dt>数据写入规则:</dt>
    <dd>1.年-月-日 时:分:秒</dd>
    <dd>2.年-月-日(不写默认时间为00:00:00)</dd>
    <dd>3.年/月/日 时:分:秒</dd>
    <dd>4.年/月/日(不写默认时间为00:00:00)</dd>
    <dd>5.月/日/年 时:分:秒</dd>
    <dd>6.月/日/年(不写默认时间为00:00:00)</dd>
    <dd>5.月-日-年 时:分:秒</dd>
    <dd>6.月-日-年(不写默认时间为00:00:00)</dd>
    <dd>7.时:分:秒 年-月-日</dd>
    <dd>8.时:分:秒 年/月/日</dd>
    <dd>9.时:分:秒 月/日/年</dd>
    <dd>10.时:分:秒 月-日-年</dd>
</dl> -->
<script type="text/javascript">
window.onload=function(){	
	times("year","month","date","h","m","s");//设置年月日,时分秒
	
	document.getElementById("year").onchange=function(){
		getdate("year","month","date");//计算当月天数
		}
	document.getElementById("month").onchange=function(){
		getdate("year","month","date");//计算当月天数
		}
	times("year1","month1","date1","h1","m1","s1");//设置年月日,时分秒
	document.getElementById("year1").onchange=function(){
		getdate("year1","month1","date1");//计算当月天数
		}
	document.getElementById("month1").onchange=function(){
		getdate("year1","month1","date1");//计算当月天数
		}
	document.getElementById("but").onclick=function(){
		cc("year","month","date","h","m","s","year1","month1","date1","h1","m1","s1","tt");//计算倒计时
		}
	}
function js(){
			var endt = new Date(startTime).getTime();
			var now1 = new Date().getTime();
			var endt1 = new Date(endTime).getTime();
			if(now1>=endt&&now1<=endt1){
				var t=endt1-now1;
				}else{
					var t=endt-now1;	
					}			
			var days    = Math.floor(t / (1000*60*60*24));
			var hours    = Math.floor(t/ 1000 / 60 / 60 - (24 * days));
			var minutes   = Math.floor(t / 1000 /60 - (24 * 60 * days) - (60 * hours));
			var seconds   = Math.floor(t/ 1000 - (24 * 60 * 60 * days) - (60 * 60 * hours) - (60 * minutes));	
			if(now1>=endt&&now1<=endt1){
				if(p==1){
					clearTimeout(timers);
					document.getElementById("tt1").innerHTML="秒杀已开始";
					p=0;
					}				
				document.getElementById(li_id).innerHTML=z(days)+"天"+z(hours)+"时"+ z(minutes)+"分"+z(seconds)+"秒";
				timer=setTimeout(js,1000)
				}else{
					if(now1<endt){
						document.getElementById("tt1").innerHTML=z(days)+"天"+z(hours)+"时"+ z(minutes)+"分"+z(seconds)+"秒";
						p=1;
						timers=setTimeout(js,1000);		
										
						}else{							
							clearTimeout(timer);
							document.getElementById(li_id).innerHTML="已结束";
							document.getElementById("tt1").innerHTML="秒杀已结束";
							}				
					}	
			}
		}
function z(i){
	if(i<10)return \'0\'+i;
	return i;
	}
</script>
</body>
</html>

  

版权声明:本文为5imoban原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/5imoban/articles/5667019.html