按下按钮开始倒计时

Countdown start on button press

本文关键字:倒计时 开始 按钮      更新时间:2023-09-26

我遇到了一个问题。我有一个按钮,它向perl脚本发送命令。在60秒内,页面将只是加载和加载。因此,我需要一个倒计时来告诉用户需要多少时间才能完成perl脚本。所以我从网上得到了他的javascript,当页面加载时,它会自动倒计时。有可能扭转这种局面吗?

http://goo.gl/cYdKg

您看到了当您没有正确地陈述您的需求时会发生什么吗?两个人做了同样的错事(对我们不利,我们之前没有澄清,tho)。

$.fn.timedDisable = function(time, callback) {
    if (time == null) {
        time = 5000;
    }
    var seconds = Math.ceil(time / 1000);
    return $(this).each(function() {
        $(this).attr('disabled', 'disabled');
        var disabledElem = $(this);
        var originalText = this.innerHTML;
        disabledElem.text( originalText + ' (' + seconds + ')');
        var interval = setInterval(function() {
            disabledElem.text( originalText + ' (' + --seconds + ')');
            if (seconds === 0) {
                disabledElem.removeAttr('disabled')
                    .text(originalText);
                clearInterval(interval);
                if (typeof callback !== 'undefined')
                    callback();
            }
        }, 1000);
    });
};
$(function() {
    $('#btnContinue').click(function() {
        $(this).timedDisable(5000, function() {
            window.alert('done');
        });
    });
});