<html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 6.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>雲棲社區-www.jb51.net 倒記時效果</title> </head> <body> <SCRIPT type="text/javascript"> <!-- var target=[] var time_id=[] function show_date_time_0(){ setTimeout("show_date_time_0()", 1000); for (var i=0,j=target.length;i<j;i++){ today=new Date(); timeold=target[i]-today.getTime(); sectimeold=timeold/1000; secondsold=Math.floor(sectimeold); msPerDay=24*60*60*1000; e_daysold=timeold/msPerDay; daysold=Math.floor(e_daysold); e_hrsold=(e_daysold-daysold)*24; hrsold=Math.floor(e_hrsold); e_minsold=(e_hrsold-hrsold)*60; minsold=Math.floor((e_hrsold-hrsold)*60); seconds=Math.floor((e_minsold-minsold)*60); if (daysold<0) { document.getElementById(time_id[i]).innerHTML="逾期,倒計時已經失效"; } else { if (daysold<10) {daysold="0"+daysold} if (daysold<100) {daysold="0"+daysold} if (hrsold<10) {hrsold="0"+hrsold} if (minsold<10) {minsold="0"+minsold} if (seconds<10) {seconds="0"+seconds} if (daysold<3) { document.getElementById(time_id[i]).innerHTML="<font color=red>"+daysold+"天"+hrsold+"小時"+minsold+"分"+seconds+"秒</font>"; } else { document.getElementById(time_id[i]).innerHTML=daysold+"天"+hrsold+"小時"+minsold+"分"+seconds+"秒"; } } } } setTimeout("show_date_time_0()", 100); //--> </SCRIPT> 距5.1(女友生日)還有: <div id="TimeCounter_0" ></div> <SCRIPT> //設定目標時間(數組元素) //target[target.length]=new Date(年,月-1,日,時,分,秒).getTime() target[target.length]=new Date(2008,04,01,00,00,00).getTime(); //設定倒計時顯示地址(數組元素) time_id[time_id.length]="TimeCounter_0" </SCRIPT> 距國家公務員考試還有(12.9): <div id="TimeCounter_1" ></div> <SCRIPT> target[target.length]=new Date(2008,11,9,09,00,00).getTime() time_id[time_id.length]="TimeCounter_1" </SCRIPT> 距奧運會還有(8.8-20:08): <div id="TimeCounter_3" ></div> <SCRIPT> target[target.length]=new Date(2008,7,8,20,8,0).getTime() time_id[time_id.length]="TimeCounter_3" </SCRIPT> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]