Pikaday.js:如何在日历中取消日期?

时间:2015-04-22 11:02:33

标签: javascript jquery pikaday

我有一个日历,我想设置几天禁用。有任何人对此有经验吗?在github上它说:

Imageview.setImageResource(imageArray[position%10]);

但我怎么能用这个呢?

disableDayFn: callback function that gets passed a Date object for each day in view. Should return true to disable selection of that day.

2 个答案:

答案 0 :(得分:1)

var bookingPicker = new Pikaday(
        {
            field: $(self.options.calendarInput, container)[0],
            container: $(self.options.calendarContainer, container)[0],
            minDate: new Date(),
            bound: false,
            firstDay: 1,
        onOpen: function () {
            this.disableDayFn(23); //<--- ???
        },
        onSelect: function (date) {

        },
        onDraw: function (date) {
            console.log("NEW MONTH")
        },
        disableDayFn: function(dateTime){
          /* here you can access each day shown and disable those in your range. To disable just return true*/
       } 
    }
);

答案 1 :(得分:0)

  

因此,您可以在选择器上看到的每个日期都会被传递,只需在该日期的函数中执行您想要的任何检查。这是一个使用日期字符串数组的示例,它使用moment.js来限定相等。

var validDateArray = ["2017-JAN-01", "2017-JAN-02", "2017-JAN-03"]
  选择器中的

disableDayFn: (dateToCheck: Date) => {

  if (validDateArray == undefined) {
    console.log("...validDateArray == undefined");
    return true;
  }

  let d1 = Moment(dateToCheck).format("YYYY-MMM-DD");

  for (let d2 of validDateArray) {
    if (d1 == d2) {
      console.log("...date is valid");
      return false; 
    }
  }

  console.log("...date is not valid");
  return true;
}