1

私はjqueryでプログラミングしたことがありません。PHPページを呼び出すときにカウントダウンを行うためにJQuery Countdownプラグインを使用していますが、タイマーが再起動しません。JQuery Countdown プラグインの「onExpiry」イベントによって呼び出される再起動関数を作成する必要があります。これは、HTMLページにあるスクリプトです。私はこの投稿をフォローしています: 自動再起動/カウントダウンタイマーのリセット ですが、日付に関するものであるため、その投稿の解決策は機能しないと思います。最大 2 時間のランダムな期間再起動する必要があります。ありがとう.....

$(document).ready(function () {
    function randRange() {
        var newTime = Math.floor(Math.random() * 30001) + 10000;
        return newTime;
    }

    function toggleSomething() {
        $('#timeval').load('ajaxTime.php?randval=' + Math.random());
        clearInterval(timer);
        lollo = parseInt(randRange());
        timer = setInterval(toggleSomething, lollo);
        $('#msg').fadeOut("slow").countdown({ *onExpiry:?????* until : +(lollo / 1000),
            format : 'HMS',
            layout : '<div id="timer">' + '<div class="timer_numbers">{hnn}:{mnn}:{snn}</div>' + '</div>'
        }).fadeIn("slow");
    }
    var timer = setInterval(toggleSomething, 1000);
});

編集:

私は解決しました:

$('#msg').countdown({until: +(lollo/1000), onExpiry: function() { setTimeout(function() { $('#msg').countdown('change', {until: +((lollo/1000) - 1)}); }, 1000); }, format: 'HMS', layout:
    '<div id="timer">'+
        '<div class="timer_numbers">{hnn}:{mnn}:{snn}</div>'+
    '</div>'
    });

誰かがより良い解決策を持っている場合は、私に連絡してください pro-zac31[at]libero.it .... !!! ありがとう :)

4

1 に答える 1

0

これはどう:

$(function() {
    function randRange() {
        return Math.floor(Math.random() * 30001) + 10000;
    }

    (function resetTimer() {
        $('#msg').fadeOut("slow", function() {
            $(this).countdown('destroy').countdown({
                until: randRange() / 1000,
                format: 'HMS',
                layout: '<div id="timer">' + '<div class="timer_numbers">{hnn}:{mnn}:{snn}</div>' + '</div>',
                onExpiry: resetTimer
            }).fadeIn("slow");
        });
    })(); //self-execute
});
于 2012-06-11T01:08:25.997 に答える