- 仅初始化一次数据选择器;告诉它从全局数组中获取有效日期
- 使用数组文字初始化全局数组,必要时通过AJAX更新
.datepicker("refresh")每当禁用/启用日期更改时(即当您通过AJAX获得新结果时)都调用该方法- 您的代码未在日期中添加前导零,因此
$.inArray
无法按预期工作
var datelist = []; // initialize empty array$("#datepicker").datepicker({ beforeShowDay: function(d) { // normalize the date for searching in array var dmy = ""; dmy += ("00" + d.getDate()).slice(-2) + "-"; dmy += ("00" + (d.getMonth() + 1)).slice(-2) + "-"; dmy += d.getFullYear(); return [$.inArray(dmy, datelist) >= 0 ? true : false, ""]; }});$("#button").click(function() { datelist = []; // empty the array $.post("/echo/html/", { // parameters here }, function() { var result = "28-02-2012,29-02-2012,01-03-2012,02-03-2012,03-03-2012,04-03-2012,05-03-2012,06-03-2012,07-03-2012,08-03-2012,09-03-2012,28-02-2012,29-02-2012,01-03-2012,02-03-2012,03-03-2012,04-03-2012,05-03-2012,06-03-2012,07-03-2012,08-03-2012,09-03-2012"; // dummy result datelist = result.split(","); // populate the array $("#datepicker").datepicker("refresh"); // tell datepicker that it needs to draw itself again });在这里演示



