javascript - jquery datepicker - add class to first 17 days - Stack Overflow

Is there a way to give a class to the first 17 days on a jquery datepicker calendar?I have tried this b

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?

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?

Share Improve this question edited Jul 26, 2013 at 10:18 Tom asked Jul 25, 2013 at 16:43 TomTom 13k50 gold badges153 silver badges247 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

maybe something like:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745273417a4619889.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信