用JS實現(xiàn)的倒計時效果
<div id="leftTime"></div>
<script type="text/javascript">
setInterval(function time(){
var o = document.getElementById("leftTime");
var nowTime = new Date(),endTime = new Date("2012/7/14 18:00:00");
var leftSecs = Math.floor((endTime.getTime() - nowTime.getTime()) / 1000);
var leftDays = Math.floor(leftSecs / (24*60*60)); //剩余的天數(shù)
var leftHour = Math.floor(leftSecs % (24*60*60) / (60*60)); //剩余的小時數(shù)
var leftMins = Math.floor(leftSecs %s (60*60) / 60); //剩余的分鐘數(shù)
var leftSec = Math.floor(leftSecs % 60); //剩余的秒數(shù)
o.innerHTML = "現(xiàn)在還剩下" + leftDays + "天" + leftHour + "小時" + leftMins + "分鐘" + leftSec + "秒";
},1000);
</script>
當然寫法不只這一種,還可以這樣寫:
setInterval("doTimeout()" , 1000); //true
setInterval(doTimeout() , 1000); //false
setInterval(function() { //truedoTimeout();
} , 5000);
setInterval(doTimeout , 1000); //true
setInterval('doTimeout' , 1000); //false