当从SELECT列表中选择一个值时,一个现有的空数组var disableddates = [];
将被填充一个'2016-03-21‘格式的日期列表。
我希望在事件发生后从数组中禁用日期,但它根本不起作用。
$( "#datepicker" ).datepicker({
beforeShowDay: DisableSpecificDates,
dateFormat: "yy-mm-dd",
// rest of the code
function DisableSpecificDates(date) {
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [disableddates.indexOf(string) == -1];
}
当我在代码运行之前用特定的日期或多个日期设置disableddates
时,它实际上会被禁用,所以这里唯一的问题是,我不能像上面提到的那样让datepicker禁用事件上的日期。
另外,如果我使用事件beforeShow
而不是beforeShowDay
,什么都不会发生。
console.log
确认数组确实正在被填充,所以我确信这只是datepicker事件的工作方式的一个问题。
有什么建议或解决办法吗?
发布于 2016-03-09 06:50:07
最后找到了一个相当简单的解决方案。每次填充数组后,我都会调用datepicker上的refresh方法。
$.each(data.response, function(i, item) {
disableddates.push(item);
});
// end array population
$( "#datepicker" ).datepicker( "refresh" );
https://stackoverflow.com/questions/35884271
复制相似问题