javascript的一些倒计时函数

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<title>实时倒计时</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body onload="Load()">
	<!-- 一些倒计时的方法,附上代码,自己理解消化 -->
	
	<!-- 方法一: -->
	<script type="text/javascript">
		function Load(){
			var dateTime=new Date();
			var strEndDate="2012/5/20";
			var endDate=new Date(strEndDate);
			var num=endDate.getTime()-dateTime.getTime();
			var miao=parseInt(num/1000%60);
			var fen=parseInt(num/1000/60%60);
			var shi=parseInt(num/1000/60/60%24);
			var tian=parseInt(num/1000/60/60/24);
			document.getElementById("djs").innerHTML=tian+"天"+shi+"时"+fen+"分"+miao+"秒";
			setTimeout(Load,1000);
		}
	</script>
	<center>倒计时:<font id="djs"></font></center>

	<!-- 方法二: -->
	<center>剩余时间:<span id="endtime">10</span></center>
	<script type="text/javascript">
	var CID = "endtime";
	if(window.CID != null)
	{
		var iTime = document.getElementById(CID).innerText;
		var Account;
		RemainTime();
	}
	function RemainTime()
	{
		var iDay,iHour,iMinute,iSecond;
		var sDay="",sHour="",sMinute="",sSecond="",sTime="";
		if (iTime >= 0)
		{
        iDay = parseInt(iTime/24/3600);
        if (iDay > 0)
        {
            sDay = iDay + "天";
        }
        iHour = parseInt((iTime/3600)%24);
        if (iHour > 0){
            sHour = iHour + "小时";
        }
        iMinute = parseInt((iTime/60)%60);
        if (iMinute > 0){
            sMinute = iMinute + "分钟";
        }
        iSecond = parseInt(iTime%60);
        if (iSecond >= 0){
            sSecond = iSecond + "秒";
        }
        if ((sDay=="")&&(sHour=="")){
            sTime="<span style='color:darkorange'>" + sMinute+sSecond + "</font>";
        }
        else
        {
            sTime=sDay+sHour+sMinute+sSecond;
        }
        if(iTime==0){
            clearTimeout(Account);
              sTime="<span style='color:green'>时间到了!</span>";
        }
        else
        {
            Account = setTimeout("RemainTime()",1000);
        }
        iTime=iTime-1;
		}
		else
		{
			sTime="<span style='color:red'>倒计时结束!</span>";
		}
		document.getElementById(CID).innerHTML = sTime;
	}
	</script>
	
	<!-- 方法三: -->
	<center><div id="time">显示倒计时</div></center>
	<script type="text/javascript">
		var time=<%=5%>;
		var t = setInterval("f1()", 1000);
		function f1()
		{
			document.all("time").innerHTML="剩余:"+time+"秒";
			time--;
			if(time<0)
			{
				clearInterval(t);
			}
		}
	</script>
	
	<!-- 方法四 -->
	<center><input type="button" onclick="qq()" id="btn" value="确定"></center>
	<script language="JavaScript">
		function qq(){
			//提交操作
			var btn = document.getElementById("btn")
			btn.disabled=true
			c(5)
		}
		function c(i){
			var btn = document.getElementById("btn")
			i--;
			if(i==0){
				btn.value = "确定"
				btn.disabled=false
			}
			else{
				btn.value = "确定("+i+")"
				setTimeout("c("+i+")",1000)	//setTimeout()函数
			}
		}
	</script>
  
</body>
</html>


你可能感兴趣的:(JavaScript,Date,XHTML,qq,function,button)