jQuery 倒计时不适用于所有版本的 IE
我在 Rails 项目之一中使用 jquery 倒计时,代码如下 -
var timeoff = new Date("#{time_format(auction.end_time)}");
$("#myDivId .timerContent").countdown({until : timeoff, onExpiry:applySold, compact : true, layout : '', serverSync: serverTime });
serverTime 方法有 -
function serverTime(){
$.get("/server_time","", function(data){
time = new Date(data);
}, "text");
return time;
}
此代码在 Firefox、safari 和 chrome 中运行良好,但在 IE 中不起作用。 在 IE 中,它呈现此 - Nan:NaN:NaN
可能是什么原因导致的?
PS 在上面的代码 i 处 var timeoff = new Date("#{time_format(auction.end_time)}");
我的时间格式为 - “2011-07-07T00:00:00+05:30”
,我的文档类型设置为 -
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
I am using jquery countdown in one of rails project with following code -
var timeoff = new Date("#{time_format(auction.end_time)}");
$("#myDivId .timerContent").countdown({until : timeoff, onExpiry:applySold, compact : true, layout : '', serverSync: serverTime });
and serverTime methods has -
function serverTime(){
$.get("/server_time","", function(data){
time = new Date(data);
}, "text");
return time;
}
This code works very well with firefox, safari and chrome but doesn't work in IE.
In IE it renders this - Nan:NaN:NaN
What might be causing this ?
P.S. In above code i at the point of
var timeoff = new Date("#{time_format(auction.end_time)}");
i have time format as - "2011-07-07T00:00:00+05:30"
and my Doc type is set as -
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有完全相同的问题,我使用 Date.parse($(".time").html) ,它对 IE 和 FF 都输出良好...当我在纯 HTML 中测试它时,它可以工作并为两个浏览器倒计时! !但它似乎 RUBY rials.js 或 JS 的加载顺序与 IE 冲突..!!!!!
在 IE 和 FIREFIOX 中测试 www.scratch22.net/testing 页面!工作正常!但不是来自实际的 Rails 应用程序!
编辑
因此,我从许多不同的地方尝试了许多不同的答案,但只能得到一个用于在 IE 的 javascript 中比较日期时间和时区的答案
** 我最初有 <%= Time.now.to_datetime %>并且没有意识到这在打印到页面时返回不同的字符串格式 **
最后一个是我可以让 IE 作为数字使用的唯一带有时区的时间格式...我也摆脱了 Parse ..我
想做的就是返回从现在到价格应该下跌的时间,
并显示倒计时...
生成的 JS 类似于
每 500 毫秒更新一次的间隔
吸取的教训...
不与
<%= Time.now.to_datetime %>
使用 <%= Time.now.to_formatted_s(:rcf822) %>反而
I have the exact SAme ISSUE, im using Date.parse($(".time").html) which outputs fine for both IE and FF... When I test this in plain HTML it works and counts down for BOTH BROWSERS!! But Its seems RUBY rials.js or the load order of the JS's are conflicting with IE..!!!!!
Test this page at www.scratch22.net/testing in BOTH IE and FIREFIOX!! works fine!! but not from within an actual rails app!!
EDIT
So I tried many many different answers from many different places and could only get one to work for comparing datetime with timezone in javascript for IE
** I originally had <%= Time.now.to_datetime %> and didnt realise that this returns a different string format when printing out to a page **
The last Was the only time format with timezone that I could get IE to work with as a number... I got rid of the Parse aswell...
All up what I wanted to do was return the time between now and when a price should drop,
and show a countdown...
Resulting JS was something like
inside of a interval updating every 500 milliseconds
The lesson learnt...
is not the same as
<%= Time.now.to_datetime %>
Use <%= Time.now.to_formatted_s(:rcf822) %> instead