我使用以下代码从日期选择器中选择多个日期:
jQuery("#m_dates")
.datepicker({
onSelect: function (dateText, inst) {
$scope.addOrRemoveDate(dateText,$scope.multi_dates,'m');
},
beforeShowDay: function (date) {
var year = date.getFullYear();
var month = $scope.padNumber(date.getMonth() + 1);
var day = $scope.padNumber(date.getDate());
// This depends on the datepicker's date format
var dateString = year + "-" + month + "-" + day;
var gotDate = jQuery.inArray(dateString, $scope.data.post.multi_dates);
if (gotDate >= 0) {
// Enable date so it can be deselected. Set style to be highlighted
return [true, "state-highlight"];
}
// Dates not in the array are left enabled, but with no extra style
return [true, ""];
},
changeMonth: true, changeYear: true, dateFormat: "yy-mm-dd",
minDate: jQuery.datepicker.parseDate($scope.data.post.date_format,$scope.data.post.start_date),
maxDate: jQuery.datepicker.parseDate($scope.data.post.date_format,$scope.data.post.end_date)
});
在更改开始日期和结束日期字段时,我想更改上述日期选择器的minDate和maxDate选项。为此,我使用了以下代码:
jQuery('#m_dates').datepicker("change", {
minDate: jQuery.datepicker.parseDate($scope.data.post.date_format,$scope.data.post.start_date)
});
jQuery('#m_dates').datepicker('change', {
maxDate: jQuery.datepicker.parseDate($scope.data.post.date_format,$scope.data.post.end_date)
});
jQuery('#m_dates').datepicker("refresh");
但是,只有点击日期选择器,上面的代码才会刷新日历日期。