我只需要在特定日期的特定时间内有一个按钮

时间:2019-06-01 08:16:58

标签: javascript jquery button

我需要一个按钮仅在星期一至星期五的中午12点至下午3点出现。在那些时候不在时,则不需要显示项目(按钮)。我们还需要为将要查看该网站的人员说明不同的时区。任何帮助将不胜感激

我的代码现在仅在下午12点至下午3点禁用按钮。我无法输入仅在特定日期有效的信息。另外,我认为时间仅占服务器的时区(太平洋标准时间),而不占用户的时区。

<a href="#" target="_blank"><input id="live" class="bttHider live" 
type="submit" onclick="showHidden(); showbttHidden();" 
value="Livestream Video - STREAMING NOW" disabled></a>

<script>
var h = new Date().getHours();

if (h >= 12 && h <= 15) {

document.getElementById('live').disabled=false;
}
</script>

1 个答案:

答案 0 :(得分:0)

var today = new Date();
  var day = today.getDay();
  var daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];
  console.log("Today is : " + daylist[day] + ".");
  if(daylist[day]!="" && daylist[day]!="Sunday"){
  var hour = today.getHours();
  var minute = today.getMinutes();
  var second = today.getSeconds();
  if(hour>="12" && (hour<=3&&minute==0)){
  $("#btn1").show();}
  else{$("#btn1").hide()}
  }
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Button Styles</h2>
  <button type="button" class="btn btn-info" id=btn1>Basic</button></div></body></html>