js 倒计时
1 <!--单位:秒--> 2 剩余时间:<span id="endtime">900000</span> 3 <script type="text/javascript"> 4 var CID = "endtime"; 5 if (window.CID != null) { 6 var iTime = document.getElementById(CID).innerText; 7 var Account; 8 RemainTime(); 9 } 10 function RemainTime() { 11 var iDay, iHour, iMinute, iSecond; 12 var sDay = "", sHour = "", sMinute = "", sSecond = "", sTime = ""; 13 if (iTime >= 0) { 14 iDay = parseInt(iTime / 24 / 3600); 15 if (iDay > 0) { 16 sDay = iDay + "天"; 17 } 18 iHour = parseInt((iTime / 3600) % 24); 19 if (iHour > 0) { 20 sHour = iHour + "小时"; 21 } 22 iMinute = parseInt((iTime / 60) % 60); 23 if (iMinute > 0) { 24 sMinute = iMinute + "分钟"; 25 } 26 iSecond = parseInt(iTime % 60); 27 if (iSecond >= 0) { 28 sSecond = iSecond + "秒"; 29 } 30 if ((sDay == "") && (sHour == "")) { 31 sTime = "<span style='color:darkorange'>" + sMinute + sSecond + "</font>"; 32 } 33 else { 34 sTime = sDay + sHour + sMinute + sSecond; 35 } 36 if (iTime == 0) { 37 clearTimeout(Account); 38 sTime = "<span style='color:green'>时间到了!</span>"; 39 } 40 else { 41 Account = setTimeout("RemainTime()", 1000); 42 } 43 iTime = iTime - 1; 44 } 45 else { 46 sTime = "<span style='color:red'>倒计时结束!</span>"; 47 } 48 document.getElementById(CID).innerHTML = sTime; 49 } 50 </script>