2

Is there a way to give a class to the first 17 days on a jquery datepicker calendar?

I have tried this but it just seems to add the class to every day...

    beforeShowDay: function(date) {
        for (i = 0; i < 17; i++) {
            return [true, 'myClass'];
        }
        return [false, ''];
    }

EDIT:

I've managed to nearly get it with the following code:

beforeShowDay: function (date) {

    if (date <= new Date().setDate(new Date().getDate()+17) && date >= new Date() ) {
        return [true, 'myClass'];
    }

    return [true, ''];

}

The only problem is that it doesn't give the class to todays date. Any ideas why?

4

1 回答 1

5

也许是这样的:

beforeShowDay: function(date) {
   var today = new Date(), maxDate;
   today.setHours(0,0,0,0);
   maxDate = new Date().setDate(today.getDate() + 17);
   if (date <= maxDate && date >= today ) {
      return [true, 'myClass'];
   }
   return [true, ''];
}

JSFIDDLE

于 2013-07-25T16:57:57.453 回答