Javascript基础数学

Javascript基础数学,javascript,jquery,math,Javascript,Jquery,Math,我正在尝试用JS执行一些非常基本的操作。我有一个倒计时,它从一个隐藏的标记中检索剩余的秒数,然后解析它。在函数的末尾,我希望它从span标记中的秒数中删除间隔计时器。目前我已经做了: parseInt($(this).find("#sqbTimestamp").text()) - 3; 然后我使用setTimeout(函数,2)每2秒运行一次(给它第二个处理空间)。但是,每次通过函数运行时,从上面的计算输出到控制台日志中的数字都是相同的 以下是完整的代码: function countdown

我正在尝试用JS执行一些非常基本的操作。我有一个倒计时,它从一个隐藏的标记中检索剩余的秒数,然后解析它。在函数的末尾,我希望它从span标记中的秒数中删除间隔计时器。目前我已经做了:

parseInt($(this).find("#sqbTimestamp").text()) - 3;
然后我使用setTimeout(函数,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("&nbsp;"); };
                        if(minutes < 60){ interval = 1000; };
                }
                i++;
        });
        setTimeout(countdownProcedure,interval);
};
函数倒计时过程(){
var区间=10000;
var i=0;
var秒=空;
console.log(c++)
$(“.rfqTbl tr”)。每个(函数(){
如果(i>0){
秒=$(this.find(#sqbTimestamp”).text();
var tsInt=parseInt($(this).find(#sqbTimestamp”).text();
变量天数=数学下限(秒/(60*60*24));
秒-=天*60*60*24;
var小时=数学地板(秒/(60*60));
秒-=小时*60*60;
var分钟=数学地板(秒/60);
秒-=分钟*60;
//$(this.find(“#sqlTimestamp”).text(newTS);
控制台日志(tsInt-3);
如果(天<1){days=”“;}
$(this.find(“#倒计时”).html(天+“天”+小时+”:“+分钟+”:“+秒);
$(this.find(“#倒计时”).append(i+“-”+秒);
如果(天数>1){
$(this.find(“#倒计时”).css({
“颜色”:“2A7F15”,
“字体大小”:“粗体”
});
};
如果(天数<1){
$(this.find(“#倒计时”).css('color','red');
$(this).find(“#倒计时前:第n个类型(1)”).css('display','none');
}
if(秒<10){$(this).find(#倒计时”).append(“”;};
如果(分钟<60){interval=1000;};
}
i++;
});
设置超时(倒计时过程,间隔);
};
This
$(This).find(“#sqbTimestamp”).html(tsInt+1)代码段更改span容器中的秒数

//运行倒计时程序
倒计时程序();
var-runNo=0;
函数倒计时过程(){
var区间=10000;
var i=0;
var秒=空;
runNo++;
$(“.rfqTbl tr”)。每个(函数(){
如果(i>0){
秒=$(this.find(#sqbTimestamp”).text();
var tsInt=parseInt($(this).find(#sqbTimestamp”).text();
$(this.find(“#sqbTimestamp”).html(tsInt+1);
变量天数=数学下限(秒/(60*60*24));
秒-=天*60*60*24;
var小时=数学地板(秒/(60*60));
秒-=小时*60*60;
var分钟=数学地板(秒/60);
秒-=分钟*60;
$(this.find(“#sqlTimestamp”).text(tsInt-3);
控制台日志(tsInt-3);
如果(天<1){days=”“;}
$(this.find(“#倒计时”).html(天+“天”+小时+:“+分钟+”:“+秒+”运行编号:“+runNo+”);
如果(天数>1){
$(this.find(“#倒计时”).css({
“颜色”:“2A7F15”,
“字体大小”:“粗体”
});
};
如果(天数<1){
$(this.find(“#倒计时”).css('color','red');
$(this).find(“#倒计时前:第n个类型(1)”).css('display','none');
}
if(秒<10){$(this).find(#倒计时”).append(“”;};
如果(分钟<60){interval=1000;};
}
i++;
});
设置超时(倒计时过程,间隔);
};

setTimeout
需要毫秒,而不是秒。我不知道每个表行中都有什么,但您似乎从未更改过#sqbTimestamp.text的值,因此每次迭代都保持不变。我不完全理解它在做什么-你能发布更多的代码或小提琴吗?看起来你没有更新#sqbtimestap的文本,所以log(tInt-3)总是一样的。“在函数结束时,我希望它从span标记中的秒数中删除间隔计时器”-我什么地方都没看到?我在小提琴上放了一个版本。如果您能提供反馈,我们将不胜感激。正如您所看到的,该功能一直在运行,但秒数保持不变。我已将一个版本置于fiddle上。如您所见,该功能保持运行,但秒数保持不变,不会减少,敬请反馈。非常感谢
//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("&nbsp;"); };
                        if(minutes < 60){ interval = 1000; };
                }
                i++;
        });
        setTimeout(countdownProcedure,interval);
};