jQuery UI Datepicker enable only specific days in array

前端 未结 1 1702
死守一世寂寞
死守一世寂寞 2020-11-29 04:22

I am trying to disable all dates in a datepicker and only enable dates which are in an array. This is the code I have so far http://jsfiddle.net/peter/yXMKC/ the problem is

相关标签:
1条回答
  • 2020-11-29 05:22

    $.inArray(dmy, availableDates) returns the index of the element, so when you compare with 1 only 14-5-2011 will match. Check for not equal to -1. Should work.

    Fiddle - http://jsfiddle.net/yXMKC/4/

    var availableDates = ["9-5-2011","14-5-2011","15-5-2011"];
    
    function available(date) {
      dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
      console.log(dmy+' : '+($.inArray(dmy, availableDates)));
      if ($.inArray(dmy, availableDates) != -1) {
        return [true, "","Available"];
      } else {
        return [false,"","unAvailable"];
      }
    }
    
    0 讨论(0)
提交回复
热议问题