我有一个问题,我的日期选择器。 我写了这段代码:
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。) 但它启用所有日期...... 我该怎么办?
答案 0 :(得分:1)
在准备好的函数中,您创建了一个日期选择器,其值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
}
});
}
答案 1 :(得分:0)
我认为应该是
$('#leftDatePicker').igDatePicker({
width: 230,
datepickerOptions: {
beforeShowDay: available, // it is a datepicker option
minDate: d,
yearRange:"2011:2014",
changeMonth: true,
changeYear: true
}
});