javascript - js gethours 和 getmonths 无法正常工作

标签 javascript jquery

<script type="text/javascript">

       $(function() {
            var hours = new Date().getHours();
            var minutes = new  Date().getMinutes();
            console.log(hours);
            console.log(minutes);
            if(hours >= 10 && minutes >=30) {
                 $("#enableOvertime").hide(); // button not hiding
      
            }
       });
       
      
    </script>
<button type="submit" id="enableOvertime">Enable Overtime </button>

我目前不明白它有什么错误。使用 console.log 显示正确的时间和分钟。 butid 不隐藏按钮。我想每天上午 10:30 之后隐藏该按钮。任何帮助,将不胜感激。

最佳答案

你的条件是错误的。它仅捕获每小时的后半部分(例如 10:30-10:59、11:30-11:59、12:30-12:59 等)。您必须将代码更改为:

if (hours >= 10 && minutes >= 30 || hours >= 11) {

关于javascript - js gethours 和 getmonths 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36760398/

相关文章:

javascript - 将 ckeditor5 集成到 Angular 项目时得到 ckeditor-duplicated-modules

javascript - Google Hangouts 扩展如何创建面板窗口?

javascript - 为什么 JavaScript 中的异步函数的 UI 不更新

javascript - 如何在具有缩放功能的 div 中适应和居中 css 家谱

jquery - jQuery Mobile changePage 功能的替代方案

javascript - 开始时 Owl Carousel 偏移量

javascript - 当用户将数据输入表单时要知道什么事件?

javascript - 有没有办法从浏览器缓存中清除/删除特定资源而不是清除整个缓存?

javascript - 标题来自 Id Youtube API v3?

javascript - 来自 Chrome 扩展程序的多个 Web 服务调用