当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Only show first Friday of every month as available to pick - jQuery UI Datepicker

问题描述:

I am trying to only allow the first Friday of every month to be selectable in my jQuery UI Datepicker and deny any other date.

I realise I could do this with a combination of PHP and jQuery by getting the date of the first Friday for X months in the future, then adding them to a javascript array that I check against within Datepicker's beforeShowDay - something like this:

var allowedDates = new Array();

allowedDates[] = <?=date("d/m/Y",strtotime("first Friday of February 2012"))?>

allowedDates[] = <?=date("d/m/Y",strtotime("first Friday of March 2012"))?>

allowedDates[] = <?=date("d/m/Y",strtotime("first Friday of April 2012"))?>

(I would of course put this in a for loop rather than typing each month manually)

The problem with this is that it is limiting due to me having to specify how far in the future to look. So is there a way with javascript to check to see if the date checked in Datepicker's beforeShowDay is the first of the month without me having to specify how far into the future to check?

Thanks!

网友答案:

this should do the trick for you:

jQuery('#datepicker').datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        var day2 = date.getDate();
        return [(day == 5 && day2 <= 7), ''];   
    }
});

As you can see here.

分享给朋友:
您可能感兴趣的文章:
随机阅读: