javascript - jquery定时器实现

标签 javascript jquery jquery-ui

全部,

是否有一个 jQuery 定时器可以启动 20 分钟的定时器并显示耗时?请给我指出一个小代码。

var austDay = new getTime();
austDay = new getSeconds(austDay);
var duration = 1200;
duration +=  austDay;

谢谢

最佳答案

不确定 jQuery 解决方案,但无论如何它都很简单:

var elapsed = 0;
var interval;
var total = 60 * 20; // 20 mins in seconds

function showElapsedTime()
{
    if(elapsed < total)
    {
        elapsed += 1;

        // If you want you can convert the seconds elapsed to minutes and seconds
        // here before you display them

        $('#elapsed').html(elapsed);
    }
    else
    {
        clearInterval(interval);
        alert('Done');
    }
}

$(function(){
    interval = setInterval(showElapsedTime, 1000);
});

其中 #elapsed 是要在其中显示已用时间的 divspan 元素。

quite a few timer plugins ,但无论如何它们都只是 setTimeoutsetInterval 的抽象,而且我不确定它们是否真的更容易使用。

关于javascript - jquery定时器实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2400227/

相关文章:

javascript - 悬停时的颜色没有改变

javascript - 如何使用 Meteor.http.call

javascript - Twitter 关注按钮 : Get the status (followed or not) of the button on load with javascript?

jquery - 始终保持 ui 自动完成功能打开

php - 根据持续时间计算结束日期

javascript - 根据度数计算方向

javascript - 我们如何在 chrome 扩展中向 gmail 撰写栏添加新按钮?是通过 javascript 还是一些 gmail api?

jquery - iframe 显示 :none not working

c# - 将二维数组发送到 Web API 服务

javascript - 更改 DIV 标签功能,如选择选项?