jQuery UI Datepicker - Disable specific days

前端 未结 6 2136
予麋鹿
予麋鹿 2020-11-29 03:20

Is there any (easy) way to set the jQuery UI Datepicker to disallow selection of specific, predetermined days?

I was able to get this approach working, however, it p

6条回答
  •  臣服心动
    2020-11-29 03:47

    You can use the beforeShowDay option. I needed to disable any day past the 28th of the month. Here is my code.

    $('.datepicker').datepicker({
        dateFormat: "yy-mm-dd",
        beforeShowDay: function(date) {
            var day = date.getDate();
            if (day > 28) {
                return [false];
            } else {
                return [true];
            }
        }
    });
    

    Here is more information about it: http://api.jqueryui.com/datepicker/#option-beforeShowDay

    The date variable passed into the beforeShowDay callback is a JavaScript date object, so it can be formatted using various libraries, a timestamp can be retrieved using date.getTime(), etc.

提交回复
热议问题