jquery datepicker onChangeMonthYear [英] jquery datepicker onChangeMonthYear
问题描述
我已经创建了一个内联日期戳。
我在 onChangeMonthYear 上遇到问题。我已经将这个例子简化为最低限度。
单击上一个或下一个,日历应该: -
- 相应地前往/下个月。
- 将当月的第一天设为当前所选日期。
- 提醒该日期
问题出在#2。
我正在使用 setDate 做到这一点,它是以无限递归结束的。因为,我在onChangeMonthYear上调用setDate。而且setDate也在内部开始onChangeMonthYear。
如果点击上一个/下一个,我该如何实现这3个。
尝试设置一个可以在事件处理程序中查询的标志,以防止无限循环:
var changingDate = false;
$('。selector')。datepicker({
onChangeMonthYear:function(year,month,inst){
if(changingDate){
return;
}
changingDate = true;
//你的setDate()调用这里
changingDate = false;
}
});
I am using the jquery ui datepicker in my app. I have created an inline datepicker. I am having a problem with onChangeMonthYear. I have simplified the example to bare minimum.
Onclick of "prev" or "next", the calendar should: -
- Go to the previous/next month accordingly.
- Set the first day of that month as the current selected date.
- alert that date
The problem is with #2.
I am using setDate to do that, and it is ending up in infinite recursion. Because, I am calling setDate inside onChangeMonthYear. And setDate is also firing onChangeMonthYear internally.
How can I achieve those 3 things when prev/next is clicked.
Try setting a flag that you can query in your event handler to prevent the infinite loop:
var changingDate = false;
$('.selector').datepicker({
onChangeMonthYear: function(year, month, inst) {
if (changingDate) {
return;
}
changingDate = true;
// your setDate() call here
changingDate = false;
}
});
这篇关于jquery datepicker onChangeMonthYear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!