JS 實現時間倒計時
<script type="text/javascript"> var maxtime = 1350057600 //截止到的日期 var now=parseInt((new Date().getTime())/1000);//獲取當前的日期 var cha_time=maxtime-now;//中間所差的時間下面方法把相差的時間組合成倒計時的字符串,然后放到頁面相應位置實現,實時刷新 function CountDown(){
if(cha_time>=0){ var day = Math.floor(cha_time/3600/24); var hour= Math.floor((cha_time/3600)%24); var minutes = Math.floor((cha_time/60)%60);
var seconds = Math.floor(cha_time%60);
msg = "離結束還有"+day+"天"+hour+"小時"+minutes+"分"+seconds+"秒"; $(".ws_sg_con_big,.ws_sg_con_small").find("dd").html(msg); --cha_time;
}
else{
clearInterval(timer);
alert("時間到,結束!");
}
}
timer = setInterval("CountDown()",1000); </script></pre>
本文由用戶 mmxn 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!