根据从后端传来的数据,我强调了几天一个月。当我cahnge一个月或一年,再次打电话Ajax调用。但是,日期选择器只显示前一个日期。我的代码如下,
$("input.dC").live('click',function() {
$(this).datepicker({
showOn:'focus',
changeMonth:'true',
changeYear:'true',
onChangeMonthYear:function(year,month,inst) {
var date = new Date(year,month-1);
obj.suggestDates(date);
$("#"+inst.id).datepicker("refresh");
},
beforeShowDay:function(date){
for(i=0;i<obj.r.length;i++) {
var m = obj.r[i];
if(date.getMonth() == m[1] && date.getDate() == m[0] && date.getFullYear() == m[2]) { return[true,"ui-state-highlight"];}
}
return[false,""];
}
}).focus();
});
obj.prototype.suggestDates=function(d){
//ajax call here
//obj.r=response;
}
我知道这里的问题。我们需要设置异步:对于AJAX调用那是假的
$.ajax({async:false});
现在工作正常。
也许这种联系是有益的:https://github.com/jtsage/jquery-mobile-datebox/issues/231
如果没有,你有没有试着让事件处理程序外,比内称之为刷新方法?
类似的东西:
// I everytime build first a getter für my jQuery-Element. So you can change your selector with changing only one method
var getDatebox = function() {
return jQuery('input.dC');
};
var refreshDatebox = function() {
getDatebox().datebox('refresh');
};
getDatebox().on('click', function() { // don't use 'live', it's deprecated
jQuery(this).datepicker({
[...]
onChangeMonthYear: function(year, month) {
var date = new Date(year, month-1);
obj.suggestDates(date);
refreshDatebox(); // call new function
},
[...]
});
});
陷入同样的问题,该日期选择器不被刷新由于像“的setDate”外部修改。我哈克的解决办法是假货鼠标离开事件
$('.hasDatepicker').find('.ui-datepicker-calendar').trigger('mouseleave')