Bootstrap Datepicker禁用所选的几天

时间:2015-03-23 16:44:47

标签: javascript jquery twitter-bootstrap

如何使用Bootstrap Datepicker禁用每月29/30/31天?

到目前为止,这是我的脚本:

<script type="text/javascript">
        $(document).ready(function () {
            var now = new Date();
            now.setDate(now.getDate());
            $('.firstPaymentDate').datepicker({
                startDate: new Date(),
                beforeShowDay:  function (date) {
                    getDate() //returns the day (0-31)
                    if (date.getDate() == 29 || date.getDate() == 30 || date.getDate() == 31) {
                        return [false, '', 'Unavaliable'];
                    }
                    return [true, ''];
                },
                format: "dd-mm-yyyy",
                todayHighlight: true,

            }).datepicker('setDate', now).attr("readonly", "readonly");
</script>

1 个答案:

答案 0 :(得分:0)

我对startDate块内的getDate()行和beforeShowDay及其工作进行了评论。默认情况下,当前日期选为startDate

检查这个工作jsFiddle:http://jsfiddle.net/arul4/hru9bfL5/1/

$('#firstPaymentDate').datepicker({
    //startDate: new Date(),
    beforeShowDay:  function (date) {
        //getDate(); //returns the day (0-31)
        if (date.getDate() == 29 || date.getDate() == 30 || date.getDate() == 31) 
        {
            return [false, '', 'Unavaliable'];
        }
        return [true, ''];
    },
    format: "dd-mm-yyyy",
    todayHighlight: true
}).datepicker('setDate', now).attr("readonly", "readonly");