我正在尝试使用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);
};发布于 2013-07-04 20:29:22
此$(this).find("#sqbTimestamp").html(tsInt + 1);代码片段更改跨度容器中的秒数。
//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);
};https://stackoverflow.com/questions/17470203
复制相似问题