beforeShowDay()jquery datepicker,限制天数不显示

时间:2012-10-26 05:34:51

标签: javascript jquery jquery-ui datepicker

我有这个代码,我希望将选项限制为仅由诊所选择的日期。

http://jsfiddle.net/pypbc/10/

    $("#datepicker").datepicker({
    dateFormat: "yy-mm-dd",
    numberOfMonths: 3,
    showButtonPanel: true,
    beforeShowDay: function(date) {

        var day = date.getDay();
        var clinic = $("#AppointmentClinicId").val();

        console.log("day:" + day);
        console.log("selected clinic:" + clinic);

        if (clinic == 1) {
            return [(date.getDay() == 1), ""];
        }

        if (clinic == 2) {
            return [(date.getDay() == 2), ""];
        }

        if (clinic == 3) {
            return [(date.getDay() == 3), ""];
        }

        if (clinic == 4) {
            return [(date.getDay() == 4), ""];
        }

        if (clinic == 5) {
            return [(date.getDay() == 5), ""];
        }

        if (clinic == 6) {
            return [(date.getDay() == 6), ""];
        }

        /*if (clinic == 0) {
            return [true, ""];
        }*/

        //return [true,''];
    }
}).val();

然而,它始终显示一个总是返回假的诊所。如果你删除beforeShowDay,它的工作原理。我知道“返回[true,''];”,如果我只有那个,它就有效。但是,无法弄清楚为什么它没有正确地选择诊所以显示允许的日期。

请帮忙!

1 个答案:

答案 0 :(得分:-1)

您尝试使用的功能不是beforeShowDay,而是onBeforeShowDay