我遇到了一个问题。我有一个按钮,它向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');
});
});
});