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() 在火狐下似乎不兼容,求大神,求兼容帝

解决方案 »

  1.   

    time_end = new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); //结束的时间红色部分是哪种语言的语法?
      

  2.   

    标签语言$!{drMeetingError.StartDateTime}相当是一个变量,会传递一个时间过来new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); 就是把传递过来的时间改成1900/8/15 23:12:12这种格式
      

  3.   

    标签语言$!{drMeetingError.StartDateTime}相当是一个变量,会传递一个时间过来new Date('$FunctionLabel.FormatDateTime($!{drMeetingError.StartDateTime})'.replace("-", "/")); 就是把传递过来的时间改成1900/8/15 23:12:12这种格式
      

  4.   

    那你还是自己在Firebug下调试吧,看看报什么错误信息。
      

  5.   

    在火狐下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>
    直接黏贴了就能用
      

  6.   

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

  7.   

    或者:
    new Date('1992-06-08 12:13:15'.split("-").join("/"))
      

  8.   


    正解。replace()字符串替换时不是全局替换的,只替换第一个找到的子串(只有第一个-符号会被替换成/)。