简体   繁体   English

IE中无法运行的JavaScript函数

[英]JavaScript function working in IE not in chrome

I am facing problem while enabling & disabling the div block in web page. 我在启用和禁用网页中的div块时遇到问题。 I need to display dvMessage block in non-working hours and dvChat in working hours. 我需要显示dvMessage在非工作时间和块dvChat中的工作时间。

For this I have written a code CheckTime as follows: 为此,我编写了如下代码CheckTime:

function CheckTime() {          
    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes()
    var time = hours + ":" + minutes
    var isweekend = currentTime.getDay();
    if ((time >= "20:00" && time <= "8:00")) {
        document.getElementById("dvMessage").style.display = "block";
        document.getElementById("dvChat").style.display = "none";
    }
    else {
        document.getElementById("dvMessage").style.display = "none";
        document.getElementById("dvChat").style.display = "block";
        //End
    }
}

Calling this function at body onload="CheckTime(); div id="dvChat" and div id="dvMessage" style="display: none;" class="message" body onload="CheckTime(); div id="dvChat"div id="dvMessage" style="display: none;" class="message"处调用此函数

But this function works in IE but not in chrome. 但是此功能在IE中有效,但在chrome中不起作用。 Is there anything else I need to do for Crome? 我还有什么需要为Crome做的吗?

Thanks in advance. 提前致谢。

Thanks, It works after currentTime is defined and adding missing Semicolons. 谢谢,它在定义currentTime并添加缺少的分号后可以工作。

 function CheckTime() {
    var currentTime = new Date();
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();
    var time = hours + ":" + minutes;
    var isweekend = currentTime.getDay();
    if ((time >= "20:00" && time <= "9:00")) {
        document.getElementById("dvMessage").style.display = "block";
        document.getElementById("dvChat").style.display = "none";
    }
    else {
        document.getElementById("dvMessage").style.display = "none";
        document.getElementById("dvChat").style.display = "block";
        //End
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM