时间JSIE与火狐不兼容问题,求大神,在线等

jianghui7897 2012-07-13 02:42:51
var time_now_server, time_now_client, time_end, time_server_client, timerID,types;
window.onload = function() {
time_end = new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); //结束的时间
alert(time_end);
time_end = time_end.getTime();

time_now_server = new Date('$FunctionLabel.CurrentDate'.replace("-", "/")); //开始的时间
time_now_server = time_now_server.getTime();
time_now_client = new Date();
time_now_client = time_now_client.getTime();
time_server_client = time_now_server - time_now_client;
setTimeout("show_time()", 1000);
types = getQueryString("type");
}

function show_time() {

var timer = document.getElementById("timer");
if (!timer) {
return;
}

var time_now, time_distance, str_time;
var int_day, int_hour, int_minute, int_second;
var time_now = new Date();
time_now = time_now.getTime() + time_server_client;
time_distance = time_end - time_now;
if (parseInt(time_distance) > 0) {
alert(1);
int_day = Math.floor(time_distance / 86400000)
time_distance -= int_day * 86400000;
int_hour = Math.floor(time_distance / 3600000)
time_distance -= int_hour * 3600000;
int_minute = Math.floor(time_distance / 60000)
time_distance -= int_minute * 60000;
int_second = Math.floor(time_distance / 1000)
alert(2);
if (int_day == 0 && int_hour == 0 && (int_minute * 60 + int_second) <= 1200 && types==1) {
GetTrainUrl();
}
if (int_hour < 10) {
int_hour = "0" + int_hour;
}
if (int_minute < 10) {
int_minute = "0" + int_minute;
}
if (int_second < 10) {
int_second = "0" + int_second;
}
alert(3);

str_time = " 距离直播还有:" +
" <span class='colordullred fontweightbold fontsize16'> " + int_day + "</span> 天" +
" <span class='colordullred fontweightbold fontsize16'> " + int_hour + "</span> 小时" +
" <span class='colordullred fontweightbold fontsize16'> " + int_minute + "</span> 分" +
" <span class='colordullred fontweightbold fontsize16'> " + int_second + "</span> 秒";

timer.innerHTML = str_time;

setTimeout("show_time()", 1000);
}
else {
clearTimeout(timerID);
timer.style.display = "none";
}
}
经测试,以上JS支持IE,但是在火狐下兼容有问题getTime(); new Date() 在火狐下似乎不兼容,求大神,求兼容帝
...全文
241 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
乌镇程序员 2012-07-13
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

注意红色字,replace方法在ie和ff下有些不同,建议用正则:
new Date('1992-06-08 12:13:15'.replace(/-/g, "/"))
[/Quote]

正解。replace()字符串替换时不是全局替换的,只替换第一个找到的子串(只有第一个-符号会被替换成/)。
jianghui7897 2012-07-13
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
注意红色字,replace方法在ie和ff下有些不同,建议用正则:
new Date('1992-06-08 12:13:15'.replace(/-/g, "/"))
[/Quote]
十分感谢。。果然是这个原因。。。嘎嘎
CNLei 2012-07-13
  • 打赏
  • 举报
回复
或者:
new Date('1992-06-08 12:13:15'.split("-").join("/"))
chenyang37 2012-07-13
  • 打赏
  • 举报
回复
注意红色字,replace方法在ie和ff下有些不同,建议用正则:
new Date('1992-06-08 12:13:15'.replace(/-/g, "/"))
jianghui7897 2012-07-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
那你还是自己在Firebug下调试吧,看看报什么错误信息。
[/Quote]
在火狐下gettime方法得不到时期的值,我把代码精简了下。大神帮我调试下被。。我已经被这个整的没脾气了
<script type="text/javascript">
var time_now_server, time_now_client, time_end, time_server_client, timerID,types;
window.onload = function() {
time_end = new Date('1992-06-08 12:13:15'.replace("-", "/")); //结束的时间
time_end = time_end.getTime();
time_now_server = new Date('1990-06-08 12:13:15'.replace("-", "/")); //开始的时间
time_now_server = time_now_server.getTime();
time_now_client = new Date();
time_now_client = time_now_client.getTime();
time_server_client = time_now_server - time_now_client;
setTimeout("show_time()", 1000);

}

function show_time() {

var timer = document.getElementById("timer");
if (!timer) {
return;
}

var time_now, time_distance, str_time;
var int_day, int_hour, int_minute, int_second;
var time_now = new Date();
time_now = time_now.getTime() + time_server_client;
time_distance = time_end - time_now;
if (time_distance > 0) {
int_day = Math.floor(time_distance / 86400000)
time_distance -= int_day * 86400000;
int_hour = Math.floor(time_distance / 3600000)
time_distance -= int_hour * 3600000;
int_minute = Math.floor(time_distance / 60000)
time_distance -= int_minute * 60000;
int_second = Math.floor(time_distance / 1000)
if (int_hour < 10) {
int_hour = "0" + int_hour;
}
if (int_minute < 10) {
int_minute = "0" + int_minute;
}
if (int_second < 10) {
int_second = "0" + int_second;
}
str_time = " 距离直播还有:" +
" <span class='colordullred fontweightbold fontsize16'> " + int_day + "</span> 天" +
" <span class='colordullred fontweightbold fontsize16'> " + int_hour + "</span> 小时" +
" <span class='colordullred fontweightbold fontsize16'> " + int_minute + "</span> 分" +
" <span class='colordullred fontweightbold fontsize16'> " + int_second + "</span> 秒";

timer.innerHTML = str_time;

setTimeout("show_time()", 1000);
}
else {
clearTimeout(timerID);
timer.style.display = "none";
}
}
</script>
<html>
<body>
<div id="timer" >
距离直播还有:
</div>
</body>
</html>
直接黏贴了就能用
乌镇程序员 2012-07-13
  • 打赏
  • 举报
回复
那你还是自己在Firebug下调试吧,看看报什么错误信息。
jianghui7897 2012-07-13
  • 打赏
  • 举报
回复
大神都睡觉了么。。。。。。。求大神。。。。
jianghui7897 2012-07-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
time_end = new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); //结束的时间

红色部分是哪种语言的语法?
[/Quote]
标签语言$!{drMeetingError.StartDateTime}相当是一个变量,会传递一个时间过来new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); 就是把传递过来的时间改成1900/8/15 23:12:12这种格式
jianghui7897 2012-07-13
  • 打赏
  • 举报
回复
标签语言$!{drMeetingError.StartDateTime}相当是一个变量,会传递一个时间过来new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); 就是把传递过来的时间改成1900/8/15 23:12:12这种格式
乌镇程序员 2012-07-13
  • 打赏
  • 举报
回复
time_end = new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); //结束的时间

红色部分是哪种语言的语法?

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧