jQuery UI DatePicker - Disable all days except first and 15th day of each month

后端 未结 2 1512
庸人自扰
庸人自扰 2021-01-02 22:50

I want to disable all days on this datepicker except the 1st and 15th of every month. I referenced this answered question, but I am only able to return one date. I\'m a novi

相关标签:
2条回答
  • 2021-01-02 23:05

    This should do the trick:

    $(function(){
        $("input").datepicker(
            {
            beforeShowDay: function (date) {
    
            if (date.getDate() == 15 || date.getDate() == 1) {
                return [true, ''];
            }
            return [false, ''];
           }
        });
    });
    

    ​ Check out the link below for a working example!

    http://jsfiddle.net/HM83u/

    0 讨论(0)
  • 2021-01-02 23:14

    Seems like this would work

    $('.selector').datepicker({
           beforeShowDay: function (date) {
           //getDate() returns the day (0-31)
           if (date.getDate() == 1 || date.getDate() == 15) {
               return [true, ''];
           }
           return [false, ''];
        }
    });
    
    0 讨论(0)
提交回复
热议问题