简体   繁体   English

使用带有联系表 7 的 jquery-ui-datepicker 禁用星期六

[英]disable saturday using jquery-ui-datepicker with contact form 7

Hello i'm trying to disable all saturdays from my calendar您好,我正在尝试从我的日历中禁用所有星期六
the calendar is contact form 7 and its using jquery-ui-datepicker日历是联系表格 7,它使用 jquery-ui-datepicker
this is my short code:这是我的短代码:


[date* your-date date-479 id:datepiicker min:today placeholder "date de reservation*" ]

and this is my Jquery code:这是我的 Jquery 代码:


jQuery(document).ready(function($) {

$("#datepiicker").datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day != 6), ''];
    }
});

});

but its not working但它不工作

 $("#datepiicker").datepicker({ beforeShowDay: function(date) { var day = date.getDay(); return [(day,= 6); '']; } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" /> <input type="date" id="datepiicker" />

the solution in my case is to check the day.就我而言,解决方案是检查当天。 If it's saturday i can reset the value and tell the user to pick something else using alert.如果是星期六,我可以重置该值并告诉用户使用警报选择其他内容。


jQuery(document).ready(function($) {

const picker = document.getElementById('datepiicker');
picker.addEventListener('input', function(e){
  var day = new Date(this.value).getUTCDay();
  if([6].includes(day)){
    e.preventDefault();
    this.value = '';
    alert("This day is not available ");
  }
});
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM