1

我的日期选择器有问题。我写了这段代码:

var d = new Date(2013, 5, 5);

    $.ig.loader({
        scriptPath: "http://cdn-na.infragistics.com/jquery/20131/latest/js/",
        cssPath: "http://cdn-na.infragistics.com/jquery/20131/latest/css/",

        resources: 'igEditors',
        ready: function () {
            $('#leftDatePicker').igDatePicker({
                width: 230,
                beforeShowDay: available,

                datepickerOptions: {

                    minDate: d,                      

                    yearRange:"2011:2014",

                    changeMonth: true,
                    changeYear: true
                }
            });


            var unAvailableDates = ["17-8-2013", "14-8-2013", "15-7-2013"];

            function available(date) {
                var dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
                if ($.inArray(dmy, unAvailableDates) != -1) {
                    return [false, "", "unAvailable"];
                } else {
                    return [true, "", "Available"];
                }
            }

        }
    });
};

(我正在使用 html 和 jquery 处理 Durandal 项目。它是 Infragistics 的日期选择器,但此属性是 jquery 的。)但它启用了所有日期......我能做什么?

4

2 回答 2

1

在您的 ready 函数中,您创建了一个日期选择器,其值beforeShowDay: available,在声明之前已分配。您需要available在创建日期选择器之前提升函数声明,因为 javascript 只提升变量定义,而不是赋值。

更新:像这样...

    ready: function () {
        var unAvailableDates = ["17-8-2013", "14-8-2013", "15-7-2013"],
            available = function(date) {
                var dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
                if ($.inArray(dmy, unAvailableDates) != -1) {
                    return [false, "", "unAvailable"];
                }
                return [true, "", "Available"];
            };

        $('#leftDatePicker').igDatePicker({
            width: 230,
            beforeShowDay: available,

            datepickerOptions: {

                minDate: d,                      

                yearRange:"2011:2014",

                changeMonth: true,
                changeYear: true
            }
        });
    }
于 2013-08-19T10:16:48.710 回答
0

我认为应该是

$('#leftDatePicker').igDatePicker({
    width: 230,

    datepickerOptions: {
        beforeShowDay: available, // it is a datepicker option

        minDate: d,                      

        yearRange:"2011:2014",

        changeMonth: true,
        changeYear: true
    }
});
于 2013-08-19T10:16:20.867 回答