如何从jquery倒计时中获取时间

时间:2011-05-12 09:18:31

标签: jquery countdown

我是jquery的新手,我设定了倒计时时间。下面是一个问题和答案。我想在用户选择答案时得到剩余时间,我该怎么做?谢谢   PS:我搜索并发现了一些名为curvyCorners的东西,据说更容易得到剩余的时间,但我不知道

$(function() {
    var newYear = new Date();
    newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1);

    $('#defaultCountdown').countdown({
        until: +30,
        compact: true,
        format: 'MS'
    });

    $('#getNow').click(function() {
        var periods = $('#curvyCorners').countdown('getTimes');
        var text = '';
        for (var i = 0; i < periods.length; i++) {
            text += periods[i] + '' + $.countdown.regional[''].labels[i] + '';
        }

        $('#curPeriods').text(text);
    });

    $('#removeCountdown').toggle(function() {
            $(this).text('Re-attach');
            $('#defaultCountdown').countdown('destroy');
        },
        function () {
            $(this).text('Remove');
            $('#defaultCountdown').countdown({
                until: +30
            });
        }
    );
});

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法:

$(selector).countdown('getTimes');

它将返回一个数字[7]数组,其中的条目是年,月,周,日,小时,分钟和秒。