<title> 演示實(shí)例:倒計(jì)時(shí)效果-精確到秒 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script language="JavaScript">
<!-- //
var overDate = 1000 * 60 * 60 * 24 * 3;//截止時(shí)間:為當(dāng)前計(jì)算機(jī)時(shí)間+3天
var NowTime = new Date();
//var EndTime= new Date(2009,01,11,0,0);
var EndTime= new Date(NowTime.getTime() + overDate);
var EndTimeMsg = EndTime.getFullYear() + "年";
EndTimeMsg = EndTimeMsg + (EndTime.getMonth()+1) + "月";
EndTimeMsg = EndTimeMsg + (EndTime.getDate()) + "日";
EndTimeMsg = EndTimeMsg + (EndTime.getHours()) + "時(shí)";
EndTimeMsg = EndTimeMsg + (EndTime.getMinutes()) + "分";
EndTimeMsg = EndTimeMsg + (EndTime.getSeconds()) + "秒";
function GetRTime(){
NowTime = new Date();
var nMS=EndTime.getTime() - NowTime.getTime();
var nD=Math.floor(nMS/(1000 * 60 * 60 * 24));
var nH=Math.floor(nMS/(1000*60*60)) % 24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
var nMS=Math.floor(nMS/100) % 10;
if(nD>= 0){
document.getElementById("RemainD").innerHTML=nD;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS + "." + nMS;
}
else {
document.getElementById("CountMsg").innerHTML= EndTimeMsg +"已過!";
}
setTimeout("GetRTime()",100);
}
window.onload=function(){
document.getElementById("EndTimeMsg").innerHTML = EndTimeMsg;
GetRTime();
}
// -->
</script>
</head>
<body>
<div id="CountMsg">
今天距離
<strong id="EndTimeMsg">XX</strong>
還有
<strong id="RemainD">XX</strong>天
<strong id="RemainH">XX</strong>時(shí)
<strong id="RemainM">XX</strong>分
<strong id="RemainS">XX</strong>秒
</div> |