首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript基础数学

Javascript基础数学
EN

Stack Overflow用户
提问于 2013-07-04 20:20:58
回答 1查看 223关注 0票数 0

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

代码语言:javascript
复制
parseInt($(this).find("#sqbTimestamp").text()) - 3;

然后,我使用setTimeout(function,2)每隔2秒运行一次(给它留出第二个处理的余地)。但是,每次运行该函数时,从上面的计算输出到控制台日志的数字是相同的。

下面是完整的代码:

代码语言:javascript
复制
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);
};
EN

回答 1

Stack Overflow用户

发布于 2013-07-04 20:29:22

$(this).find("#sqbTimestamp").html(tsInt + 1);代码片段更改跨度容器中的秒数。

代码语言:javascript
复制
//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);
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17470203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档