每周仅在jQuery UI日期选择器中显示两天

时间:2019-09-10 06:45:41

标签: jquery-ui jquery-ui-datepicker

我只需要在jQuery UI日历中显示MondayThursdays。我只能启用Monday,但是不确定如何将Thursdays添加到返回列表中? 您还可以让我知道如何不显示其他日期(而不是禁用渲染按钮)吗?

$(function() {
  $("#datepicker").datepicker({
    beforeShowDay: function(date) {
      var day = date.getDay();
      return [(day == 1)];
    }
  });
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Date:
<div id="datepicker"></div>

1 个答案:

答案 0 :(得分:1)

也添加星期四的条件。如果要隐藏其他日子,请使用css

$(function() {
  $("#datepicker").datepicker({
    beforeShowDay: function(date) {
      const day = date.getDay();
      const enable=(day === 1||day===4);
      return [enable,enable?'':'hide'];
    }
  });
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
.hide{
     visibility: hidden;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Date:
<div id="datepicker"></div>

相关问题