【发布时间】:2015-09-23 17:52:18
【问题描述】:
我见过使用onBeforeShowDay 的解决方案,但这不是我需要的。我需要的是在更改月份或年份时,我需要通过 AJAX 获取日期列表,然后使用该列表禁用当前月份的日期。
示例
$('#date_input').datepicker( "option", "onChangeMonthYear", function(year,month,inst) {
// Perform AJAX call and get the list
$.ajax({
url: ajaxUrl,
type: "post",
data: serializedData,
async: false,
success: function (data) {
// Here is where I want to update the display
// and use the returned data as the basis for the disabled list
// of the current month.
// Let's say:
// data = ['2015-10-15','2015-10-25','2015-10-13'];
}
});
});
编辑
感谢您的解决方案。具体来说,我通过动态添加回调来使用动态方法。同样重要的是,AJAX 调用需要有 async: false 才能在数组上获得正确的数据集。
$('#date_input').datepicker( "option", "onChangeMonthYear", function(year,month,inst) {
// The ajax call.
});
所以我只是按照答案并补充说:
$('#date_input').datepicker( "option", "beforeShowDay", function(date) {
// Update the list.
});
再次感谢!
【问题讨论】:
-
没问题,很高兴你修好了!
标签: javascript jquery datepicker jquery-ui-datepicker