全部,
是否有一个 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
是要在其中显示已用时间的 div
或 span
元素。
有quite a few timer plugins ,但无论如何它们都只是 setTimeout
和 setInterval
的抽象,而且我不确定它们是否真的更容易使用。
关于javascript - jquery定时器实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2400227/