English 中文(简体)
Javascrat 倒计时 - 不倒计数
原标题:Javascript countdown - not counting down

我有一个倒计时脚本, 它从设定的时间中获取实时时间, 并从设定的时间中减去它。 它的作用与它不更新的事实不同, 除非您刷新您的页面。 在我函数的底部设置 Interval 指示函数每秒运行一次, 但是它似乎没有这样做...

有人能帮忙吗?

http://jsfidle.net/4yMZy/"rel="nofollow" >http://jsfidle.net/4yMZy/

最佳回答

您的代码还有其他问题。 您应该通过 Jslint 或 < a href=> http:// www.jshint. com/" rel= 'no follow'>jshint 运行 。

如果将您的代码更改为 , http://jsfiddle.net/4yMZy/7" rel=“ no follow” >http://jsfiddle.net/4yMZy/7/

所以它会根据设定的间隔时间获取时间并更新秒数 。

Edit: jsfiddle actually provides a button for that on the top.

问题回答

每次 ccount down 运行时,它都会计算剩下的时间, 像这样 :

nDates = new Date(datetime);
xDay = new Date("Fri, 26 May 2012 16:34:00 +0000");
timeLeft = (xDay - nDates);

datetime 的值从未从一个运行到另一个运行变化。 因此, CountDown 正在不断运行, 但总是比较两个日期之间的差异。 由于使用相同的两个日期, 差异总是一样, 所以您看不到任何倒计时发生 。

您可以将 nDates = new Dates( datetime); 更改为 nDates = new Dates (); , 并且它会开始倒计数, 但我不知道你为什么从某些服务器获得 datetime





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签