English 中文(简体)
j 写时间
原标题:jquery timer write time remaining

我有一个段落,希望把第二段放在这个时间上:

传真:

<p>xx seconds remaining</p>

Java:

window.setInterval(retrieveLog, 20000);

我如何能够这样做?

最佳回答

当你打电话时,储存时间:

var end = (new Date).getTime() + 20000 * 1000; // current time in ms since 1/1/1970, plus the interval time
window.setInterval(retrieveLog, 20000);

并添加一个更新案文的间隔:

var interval = setInterval(function() {
    var now = (new Date).getTime();
    $("p").text(Math.floor(( end - now ) / 1000));
    if(now > end) clearInterval(interval);
}, 1000);

http://jsfiddle.net/pimvdb/b25KR/

问题回答




相关问题
How do I wait for a TTimer to finish?

I have a TFrame (fraDisplay) with a TTimer (timAnimateDataChange). The timer is used to control a small animation. In the form containing the frame I want to have a method that does something like ...

How to tell if an ajax timer has gone off at page_load

I have a web application and I m attempting to put an ajax timer control in it to give me a post back every 10-20 seconds. (possibly longer depending on performance). I have a lot of dynamically ...

Got an error 1120 ~ Access of undefined property

This is not your typical 1120. I know better than to have buttons/MCs without instance names on the timeline. Nope, this problem resides in a I timer I built from script I found online. The undefined ...

what is the right way to call the Timer ElapsedEventHandler

i have a timer that calls its even handler method every 30 seconds. but i want to initialy call this method. the signature of the event handler method is void TimerElapsed_GenerateRunTimes(object ...

Timer for a polling windows service

I wrote a Timer class in order to use it within a windows service that is polling another system. I did this because I had two issues that the System.Timers.Timer is not addressing. The Elapsed ...

Using C# Timer to stop executing a Program

I want a program to stop executing for a certain amount of time. And i want this to happen in regular intervals. For example, i want a program to run for 5 minutes and then it should stop for 2 ...

热门标签