我目前正尝试在maxDate
和datepicker
上设置maxDate: '<%= courseEndDate.ToString("dd-MM-yy") %>'
但是当设置在datepicker上时,
$('#<%= tbStartDate.ClientID %>').datepicker({
dateFormat: 'dd-MM-yy',
changeMonth: true,
minDate: 0,
maxDate: '<%= courseEndDate.ToString("dd-MM-yy") %>',
beforeShowDay: function (date) {
var string = jQuery.datepicker.formatDate('yy/mm/dd', date);
return [array.indexOf(string) == -1]
},
onSelect: function (date) {
var selectedDate = new Date(date);
var msecsInADay = 86400000;
var endDate = new Date(selectedDate.getTime() + msecsInADay);
$('#<%= tbEndDate.ClientID %>').datepicker("option", "minDate", endDate);
}
});
Datepicker整个日历变为禁用状态。我尝试提醒maxDate和
<%= courseEndDate.ToString("dd-MM-yy") %>
给了我'24-12-16'
。所以一切似乎都没问题,但日历已被禁用..
我可以知道为什么会这样吗?
答案 0 :(得分:0)
为什么24-12-16
成为格式为24-December-2016
的日期选择器的有效设置?
您必须将该日期从给定格式解析为日期对象
$('#<%= tbStartDate.ClientID %>').datepicker({
dateFormat: 'dd-MM-yy',
changeMonth: true,
minDate: 0,
maxDate: $.datepicker.parseDate('dd-mm-y','<%= courseEndDate.ToString("dd-MM-yy") %>'),
beforeShowDay: function(date) {
var string = jQuery.datepicker.formatDate('yy/mm/dd', date);
return [array.indexOf(string) == -1]
},
onSelect: function(date) {
var selectedDate = new Date(date);
var msecsInADay = 86400000;
var endDate = new Date(selectedDate.getTime() + msecsInADay);
$('#<%= tbEndDate.ClientID %>').datepicker("option", "minDate", endDate);
}
});