jQuery倒计时到期 [英] Jquery countdown On Expiry

查看:120
本文介绍了jQuery倒计时到期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助.我在页面上放置一个jQuery倒数计时器.我正在使用的倒计时是 http://keith-wood.name/countdown.html 我所使用的需要的是一个倒计时到期时,它将倒计时到另一个日期.因此,例如,它将倒计时至1/08/2015.当它达到2015年1月1日时,我希望它倒计时到另一个日期.因此,从2015年1月8日开始,它将倒数至2015年5月8日.我希望这是有道理的.我已经成功地将倒数计时本身放在了页面上.只是到期日,我遇到了麻烦.

I need some help. I am putting a jquery countdown timer on a page. the countdown I am using is http://keith-wood.name/countdown.html what I need is when one countdown expires, it will then count down to another date. So for example it will countdown to 1/08/2015. When it reaches 1/08/2015 I then want it to count down to another date. So from 1/08/2015 it will then count down to 5/08/2015. I hope that makes sense. I have successfully put the countdown itself on the page. it is just the On expiry I am having trouble with.

这是示例中的脚本.

<script>
    $(function () {
        var austDay = new Date();
        austDay = new Date(2015, 11 - 1, 7);
        $('#defaultCountdown').countdown({until: austDay});
        $('#year').text(austDay.getFullYear());
    });
</script>

它显示在此标签中

<center><div id="defaultCountdown"></div></center>

我为此做出了努力.这是我所能获得的,但我也能做到.任何帮助将不胜感激

I have made an effort towards it. This is as far as I have got but it is also as far as I can go. Any help would be greatly appreciated

$(function () {
    var austDay = new Date();
    FirstDay = new Date(2015, 11 - 1, 7);
    SecondDay = new Date (2015, 11 - 1, 9);
    $('#defaultCountdown').countdown({until: FirstDay});
});

应该提到的是总共要倒数4个日期!

推荐答案

您有可以利用的onExpiry事件,下面只是一个示例,您可以怎么做!不知道它是否有效!可能是您必须反复试验.

You have onExpiry event which you can utilize and below is just a sample how you could do! Not sure if it works or not!! May be you have to trial and error.

首先设置一个全局变量,以检查计数是否完成:

set a global variable first to check once count has been done:

var count=0;

$(function () {
    var austDay = new Date();
    austDay = new Date(2015, 11 - 1, 7);
    $('#defaultCountdown').countdown({until: austDay,onExpiry: liftOff});
    $('#year').text(austDay.getFullYear());
});

function liftOff() { 
     if(count==0)
     {
        $('#defaultCountdown').countdown({until: newDate});
        count=1;
     }
     else
        count=0;
}

您可以在 此处

You can find the options here

更新

好吧,只需按原样复制并粘贴下面的代码即可!!

Ok just copy and paste this below code as it is!!

已测试

此处演示

DEMO HERE

var count=0; //a global variable

$(function () {
    shortly = new Date(); 
    shortly.setSeconds(shortly.getSeconds() + 5.5); //for time being this will run for 5 seconds
    $('#defaultCountdown').countdown({until: shortly,onExpiry: liftOff}); 
});

function liftOff() { 
//function that gets called on expiry
   if(count==0) //check already done 2nd time, if not get in
   {
        shortly = new Date(); 
        shortly.setSeconds(shortly.getSeconds() + 5.5); //again do it for 5 secs
        $('#defaultCountdown').countdown('option',{until: shortly});
        //set an option here for the same counter again
        count=1; //make this 1
   }
   else
       count=0;
}

上面的代码位于 上面的演示

The above code is present at the end of javascript section in the above demo given

这篇关于jQuery倒计时到期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆