简体   繁体   English

仅允许月份日期选择器中的最后一个星期五对我不起作用

[英]Only allow the last friday in month date picker don´t work for me

I want to enable only the last Friday in each month in my datepicker.我只想在我的日期选择器中启用每个月的最后一个星期五。 In another example I found a code-snippet but it doesn't work for me.在另一个示例中,我找到了一个代码片段,但它对我不起作用。 Maybe my picker uses other attribute names?也许我的选择器使用其他属性名称?

How I can do this?我怎么能做到这一点?

var monthDays = new Date(date.getFullYear(),date.getMonth() + 1,0).getDate(); 
var day = date.getDay(); 
return [( (day==5 && date.getDate() > monthDays - 7 )), '']; 
}

Here is the codepen for the tracker这是跟踪器的代码笔

Your snippet is correct, but you need to place it in the constructor like this:您的代码段是正确的,但您需要将它放在构造函数中,如下所示:

jQuery('#datetimepicker').datetimepicker({
 allowTimes:[
  '10:00', '11:00', '12:00','14:00'
 ],
  beforeShowDay: function(date) {
      const monthDays = new Date(date.getFullYear(),date.getMonth() + 1,0).getDate();
      const day = date.getDay();
      return [( (day==5 && date.getDate() > monthDays - 7 )), ''];
    }
});

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

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