按时间启用HTML按钮

Enable HTML button by time

本文关键字:按钮 HTML 启用 时间      更新时间:2023-09-26

我的网站上有一个HTML按钮:

<button id="upload" style="display:none;">  SIGN IN  </button>

我需要禁用该按钮,除了每小时25到35分钟和55到05分钟之间。如果有人能帮忙,我将不胜感激,因为我只能找到两次javascript,而且它每天只禁用一次按钮,而不是每小时两次。

非常感谢。

下面是一个实现示例:

<html>
<head>
<script>
onload = function() {
    var elt = document.getElementById("upload");
    var minutes = new Date().getMinutes();
    if((minutes > 24 && minutes < 36)||(minutes > 54 && minutes < 06)) {
        elt.style.display = 'inline';
    } else {
        elt.style.display = 'none';
    }
}
</script>
<head>
    <body>
        <button id="upload" style="display:none;"> SIGN IN </button>
    </body>
</html>

您也可以使用此函数在以下两者之间进行检查:

<html>
<head>
<script>   
onload = function() {
    var element = document.getElementById("upload");
    var minutes = new Date().getMinutes();
    if (check_between(minutes,25,35) || check_between(minutes,54,06)){
        element.style.display = 'inline';
    } else {
        element.style.display = 'none';
    }
    function check_between(minutes,n1,n2){ 
      if (minutes > n1 && minutes < n2){
        return true;
      }else{
        return false;
      }
    }   
}
</script>
<head>
    <body>
        <button id="upload" style="display:none;"> SIGN IN </button>
    </body>
</html>