简体   繁体   English

Javascript 文件突然停止工作,没有任何变化

[英]Javascript file suddenly stopped working with no changes

So I got help on this code earlier and it was working before perfectly.所以我早些时候得到了关于这段代码的帮助,并且它之前工作得很好。 However, upon opening VS Code again the code no longer responds with zero errors.但是,再次打开 VS Code 后,代码不再以零错误响应。

    var runned = false;
    var d = new Date();
    if (d.getHours(5) == 5 && !runned) {
    alert("Hello");
    runned = true;
    }

The code is simply supposed to get the current hour and return an alert.该代码只是应该获取当前时间并返回警报。 I verified that the js file was connected to the HTML file with some other code and it worked.我验证了 js 文件已连接到带有其他代码的 HTML 文件并且它有效。

var runned = false;
    var d = new Date();
    if (d.getHours() == 5 && !runned) {
    alert("Hello");
    runned = true;
    }
  1. getHours() doesn't take parameters getHours()不带参数
  2. getHours uses the 24-hour clock model, ie 0-23 so 5 is 5 am but 17 is 5pm getHours使用 24 小时制 model,即 0-23 所以 5 是早上 5 点,但 17 是下午 5 点
  3. d.getHours() as used above without an argument makes it work in all use case scenarios上面使用的没有参数的d.getHours()使其适用于所有用例场景

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

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