我正在尝试使用JS执行非常基本的操作。我有一个倒计时器,它从隐藏标签中检索剩余的几秒钟,然后解析它。在函数结束时,我希望它从span标记中的大量秒数中删除间隔计时器。目前我已经完成了:
parseInt($(this).find("#sqbTimestamp").text()) - 3;
然后我使用setTimeout(function,2)每2秒运行一次(给它一个第二个处理余地)。但是,每次运行函数时,从上面的计算输出到控制台日志中的数字都是相同的。
以下是完整代码:
function countdownProcedure(){
var interval = 10000;
var i = 0;
var seconds = null;
console.log(c ++)
$(".rfqTbl tr").each(function(){
if(i > 0){
seconds = $(this).find("#sqbTimestamp").text();
var tsInt = parseInt($(this).find("#sqbTimestamp").text());
var days = Math.floor(seconds / (60*60*24));
seconds -= days * 60 * 60 * 24;
var hours = Math.floor(seconds / (60*60));
seconds -= hours * 60 * 60;
var minutes = Math.floor(seconds / 60);
seconds -= minutes * 60;
//$(this).find("#sqlTimestamp").text(newTS);
console.log(tsInt - 3);
if(days < 1){ days=""; }
$(this).find("#countDown").html(days + "<pre> Days</pre> " + hours + "<pre>:</pre>" + minutes + "<pre>:</pre>" + seconds);
$(this).find("#countDown").append(i + " - " + seconds);
if(days > 1){
$(this).find("#countDown").css({
'color':'#2A7F15',
'font-weight':'bold'
});
};
if(days < 1){
$(this).find('#countDown').css('color','red');
$(this).find('#countDown pre:nth-of-type(1)').css('display','none');
}
if(seconds < 10){ $(this).find("#countDown").append(" "); };
if(minutes < 60){ interval = 1000; };
}
i++;
});
setTimeout(countdownProcedure,interval);
};
答案 0 :(得分:0)
此$(this).find("#sqbTimestamp").html(tsInt + 1);
代码段更改了span容器中的秒数。
//Run countdown proecudure
countdownProcedure();
var runNo = 0;
function countdownProcedure(){
var interval = 10000;
var i = 0;
var seconds = null;
runNo++;
$(".rfqTbl tr").each(function(){
if(i > 0){
seconds = $(this).find("#sqbTimestamp").text();
var tsInt = parseInt($(this).find("#sqbTimestamp").text());
$(this).find("#sqbTimestamp").html(tsInt + 1);
var days = Math.floor(seconds / (60*60*24));
seconds -= days * 60 * 60 * 24;
var hours = Math.floor(seconds / (60*60));
seconds -= hours * 60 * 60;
var minutes = Math.floor(seconds / 60);
seconds -= minutes * 60;
$(this).find("#sqlTimestamp").text(tsInt - 3);
console.log(tsInt - 3);
if(days < 1){ days=""; }
$(this).find("#countDown").html(days + "<pre> Days</pre> " + hours + "<pre>:</pre>" + minutes + "<pre>:</pre>" + seconds + "<pre>Run Number: " + runNo + "</pre>");
if(days > 1){
$(this).find("#countDown").css({
'color':'#2A7F15',
'font-weight':'bold'
});
};
if(days < 1){
$(this).find('#countDown').css('color','red');
$(this).find('#countDown pre:nth-of-type(1)').css('display','none');
}
if(seconds < 10){ $(this).find("#countDown").append(" "); };
if(minutes < 60){ interval = 1000; };
}
i++;
});
setTimeout(countdownProcedure,interval);
};