Hul*_*ulk 2 javascript jquery jquery-ui
所有,
是否有一个jQuery计时器,可以启动计时器20分钟,并显示时间已过?请指出一个小代码.
var austDay = new getTime();
austDay = new getSeconds(austDay);
var duration = 1200;
duration += austDay;
Run Code Online (Sandbox Code Playgroud)
谢谢
不确定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);
});
Run Code Online (Sandbox Code Playgroud)
当#elapsed被一个div或span要显示在经过时间的元素.
有很多 计时器 插件,但它们都只是抽象setTimeout而且setInterval无论如何,我不确定它们使用起来真的更简单.