在你提供的代码中点击战斗它将完成战斗动作并填充进度条3次(等于var auto)如果你让它完成然后再点击战斗进度条将达到val 25并冻结。为什么这样,我该如何解决?
var auto = 3;
var nb = 0;
var progress = function(sec) {
if($('#bar').val() === 0) {
$('#dam').html("You have hit the " + $('#monsters').val() + " for 5 damage").fadeIn(400);
}
if($('#bar').val() >= 75) {
$('#dam').html("You have hit the " + $('#monsters').val() + " for 5 damage").fadeOut(800);
}
var interval = 1000; //milliseconds
setTimeout(function() {
sec = sec + 25;
$('#bar').val(sec);
if (sec > 100) {
$('#bar').val(0);
sec = 0;
nb++;
}
if (nb < auto) progress(sec); //call self with new value
}, interval)
}
$('#battle').click(function() {
progress(0); //initialize progress bar
});
答案 0 :(得分:1)