Javascript 基于选择值更改禁用jQueryUI日期选择器日期
从选择列表中选择值时,现有空数组Javascript 基于选择值更改禁用jQueryUI日期选择器日期,javascript,php,jquery,jquery-ui,datepicker,Javascript,Php,Jquery,Jquery Ui,Datepicker,从选择列表中选择值时,现有空数组var disableddates=[]以“2016-03-21”格式填充日期列表 我希望jQueryUIDatePicker在事件发生后禁用数组中的日期,但它根本不起作用 $( "#datepicker" ).datepicker({ beforeShowDay: DisableSpecificDates, dateFormat: "yy-mm-dd", // rest of the code functio
var disableddates=[]代码>以“2016-03-21”格式填充日期列表
我希望jQueryUIDatePicker在事件发生后禁用数组中的日期,但它根本不起作用
$( "#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事件工作方式的问题
有什么建议或解决方案吗?终于想出了一个相当简单的解决方案。每次填充数组后,我都在datepicker上调用refresh方法
$.each(data.response, function(i, item) {
disableddates.push(item);
});
// end array population
$( "#datepicker" ).datepicker( "refresh" );