Javascript 按钮时间和日期相关

Javascript 按钮时间和日期相关,javascript,button,time,Javascript,Button,Time,该按钮应在给定的时间和日期启用,并在屏幕上显示警报消息 每次我点击按钮,若条件不满足,则应显示警报消息,否则下一个给定链接或窗口将打开 <!DOCTYPE html> <html lang="en"> <head> <style> p.font { color: #0000cc; font-size: 40px; font-weight: bold; font-family: "Time

该按钮应在给定的时间和日期启用,并在屏幕上显示警报消息

每次我点击按钮,若条件不满足,则应显示警报消息,否则下一个给定链接或窗口将打开

<!DOCTYPE html>
<html lang="en">

<head>
  <style>
    p.font {
      color: #0000cc;
      font-size: 40px;
      font-weight: bold;
      font-family: "Times New Roman", Times, serif;
    }

    .button {
      background-color: #0000cc;
      /* blue */
      border: none;
      color: white;
      padding: 16px 32px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 16px;
      margin: 4px 2px;
      -webkit-transition-duration: 0.4s;
      /* Safari */
      transition-duration: 0.4s;
      cursor: pointer;
    }

    .button1 {
      background-color: white;
      color: black;
      border: 2px solid #00004d;
      border-radius: 20px;
    }

    .button1:hover {
      background-color: #0000cc;
      color: white;
    }
  </style>
  <meta charset="UTF-8" />
  <script src="jquery-3.1.1.min.js">
  </script>
  <script>
    var thisDay = new Date().getDate();
    var thisTime = new Date().getHours();
    var thismin = new Date().getMinutes();

    function checkButton() {
      if ((thisTime >= 08 && thisTime <= 19) && (thisDay >= 07 && thisDay <= 16)) {
        $(".button button1").prop("disabled", false);
        $('.button button1').click(function() {
          window.location = 'http://www.google.com';
        });
      }
      printAlert();
    }

    function printAlert() {
      window.alert('We are not accepting entries right now.');
    }
  </script>
</head>

<body>
  <p class="font">Please Wait! Exam will start at....... </p>
  <button class="button button1">Aptitude Exam</button>
  <script>
    checkButton();
  </script>
</body>

</html>

p、 字体{
颜色:#0000cc;
字体大小:40px;
字体大小:粗体;
字体系列:“泰晤士报新罗马”,泰晤士报,衬线;
}
.按钮{
背景色:#0000cc;
/*蓝色的*/
边界:无;
颜色:白色;
填充:16px 32px;
文本对齐:居中;
文字装饰:无;
显示:内联块;
字体大小:16px;
利润:4倍2倍;
-webkit转换持续时间:0.4s;
/*狩猎*/
过渡时间:0.4s;
光标:指针;
}
.按钮1{
背景色:白色;
颜色:黑色;
边框:2px实心#00004d;
边界半径:20px;
}
.按钮1:悬停{
背景色:#0000cc;
颜色:白色;
}
var thisDay=新日期().getDate();
var thisTime=new Date().getHours();
var thismin=new Date().getMinutes();
函数checkButton(){
如果((ThistTime>=08&&ThistTime=07&&ThistDay这将帮助您:

    <!DOCTYPE html>
      <html lang="en">
         <head>
            <style>
               p.font {
                  color: #0000cc;
                  font-size: 40px;
                  font-weight: bold;
                  font-family: "Times New Roman", Times, serif;
               }

              .button {
                  background-color: #0000cc;
                  /* blue */
                  border: none;
                  color: white;
                  padding: 16px 32px;
                  text-align: center;
                  text-decoration: none;
                  display: inline-block;
                  font-size: 16px;
                  margin: 4px 2px;
                  -webkit-transition-duration: 0.4s;
                  /* Safari */
                  transition-duration: 0.4s;
                  cursor: pointer;
               }

               .button1 {
                    background-color: white;
                    color: black;
                    border: 2px solid #00004d;
                    border-radius: 20px;
               }

               .button1:hover {
                    background-color: #0000cc;
                    color: white;
               }

               .button-disabled {
                    background-color: grey;
               }

               .button-disabled:hover {
                    cursor: not-allowed;
               }
            </style>
            <meta charset="UTF-8" />
            <script src="https://code.jquery.com/jquery-3.2.1.js"></script>
            <script>
               var thisDay = new Date().getDate();
               var thisTime = new Date().getHours();
               var thismin = new Date().getMinutes();

               var checkButton = function() {
                   //Edit Done Here
                   if ((thisTime >= 08 && thisTime <= 22) && (thisDay >= 07 && thisDay <= 16)) {
                       $(".button").prop("disabled", false);
                       alert('Enable'); // For understanding - remove this later
                   } else {
                       $(".button").removeClass("button1");
                       $(".button").addClass("button-disabled");
                       $(".button").prop("disabled", true);
                       //remove the enabled button class if not in mentioned time frame
                       $(".font").html('We are not accepting entries right now. Please visit during the allowed hours.');
                       alert('Disable'); // For understanding - remove this later
                    }
                }

              var buttonClicked = function() {
                   window.location = 'http://www.google.com';
              }

            //Edit Done Here
    </script>
    </head>
    <body>
        <!-- Edit Done Here -->
        <p class="font">Please Wait! Exam will start at....... </p>
        <!-- Edit Done Here -->
        <button class="button button1" onClick="buttonClicked();" disabled>Aptitude Exam</button>
        <script>
           checkButton();
        </script>
    </body>
 </html>

p、 字体{
颜色:#0000cc;
字体大小:40px;
字体大小:粗体;
字体系列:“泰晤士报新罗马”,泰晤士报,衬线;
}
.按钮{
背景色:#0000cc;
/*蓝色的*/
边界:无;
颜色:白色;
填充:16px 32px;
文本对齐:居中;
文字装饰:无;
显示:内联块;
字体大小:16px;
利润:4倍2倍;
-webkit转换持续时间:0.4s;
/*狩猎*/
过渡时间:0.4s;
光标:指针;
}
.按钮1{
背景色:白色;
颜色:黑色;
边框:2px实心#00004d;
边界半径:20px;
}
.按钮1:悬停{
背景色:#0000cc;
颜色:白色;
}
.按钮已禁用{
背景颜色:灰色;
}
.按钮已禁用:悬停{
光标:不允许;
}
var thisDay=新日期().getDate();
var thisTime=new Date().getHours();
var thismin=new Date().getMinutes();
var checkButton=函数(){
//编辑完成这里
如果((这次>=08&&ThistTime=07&&ThistDay)
能力倾向测验
选中按钮();

请注意,您不能为禁用的按钮提供单击操作;为此,我替换了现有“p”元素的内部html。

请格式化您的代码以提高可读性,并编写一个适当的标题。您的jquery选择器上的button1之前是否缺少一个点?例如
$('.button.button1'))
但是先生,我面临的另一个问题是,我的电脑时间不是标准时间。。。。。。。