1. 程式人生 > >javascript定時器倒計時自定義時間迴圈

javascript定時器倒計時自定義時間迴圈

html> head , body...此處省略。。
<div class="TitAlis clearfloat">
    <h3>健康團

        <span class="hotDp"><a class="fontRed" href="#">每天一次限時優惠 一定要把握機會喲</a></span>

        <span class="right zptime" id="zptime">本場次剩餘時間

            <label>

            <em class="TimeRed" id="houre">00</em>

            :

            <em class="TimeRed" id="minute">00</em>

            :

            <em class="TimeRed" id="second">00</em>

            </label>

        </span>

</h3>

<script>

window.onload = function(){

var houre= "00";

var minute = "00";

var second = 10;

setInterval(function() {

second--;

if(houre<=0 && second <=0 && minute <=0) {

houre= "02";

minute = 29;

second = 59;

}; //當分鐘和秒鐘都為00時,重新給值

if(second <=0) {

second = 59;

minute--;

if(minute <=0){

houre--;

if(minute < 10) minute = "0" + minute;

minute = 59;

if(houre<10){

if(houre<=0) houre=0;

houre = "0" + houre

}

}

}; //當秒鐘為00時,秒數重新給值

if(second < 10) second = "0" + second;

$("#houre").text(houre);

$("#minute").text(minute);

$("#second").text(second);

}, 1000);

}

</script>

</div>