jquery ui datepicker onselect inst 目标
所以我有一个我认为非常基本的问题,但我一生都无法弄清楚。单击后如何引用选定的日期元素(dom)。我已经尝试过:
$("#eventCalendar").datepicker({
onSelect: function(dateText,inst){
var activeDateObj = $("#eventCalendar").find('.ui-state-active');
}
});
这会返回一个对象,但我认为它引用了先前选择的元素;因为类中尚未应用到新元素。我真的很惊讶 inst 对象不包含对单击元素的引用。我通过在变量声明周围包裹一个快速超时来实现此方法,但这非常脏,我想知道是否有更好的方法。提前致谢。
So I have what I think is a pretty basic question but I cant for the life of me figure it out. How do you reference the selected date element (dom) once clicked. I have tried this:
$("#eventCalendar").datepicker({
onSelect: function(dateText,inst){
var activeDateObj = $("#eventCalendar").find('.ui-state-active');
}
});
This returns an object but I think it references the previously selected element; as in the class has not yet been applied to the new element. I'm really surprised the inst object doesn't contain some reference to the clicked element. I got this method to work by wrapping a quick timeout around the variable declaration but this is pretty dirty and I want to know if there is a better way. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回应OP的评论。
据我所知,每次选择一天时,日历似乎都会重新加载包含该月各天的表格,当您更改月份时,它也会这样做。
如果您使用
.live('click',function(){...})
这应该允许您附加您的函数。对于选择器来说,这样的东西可能是最好的。
您现在只需计算出选择了哪个日期。
In Response to comments on OP.
From what I can tell the calendar seems to reload the table containing the days of the month each time a day is selected, it does this when you change months also.
If you use
.live('click',function(){...})
this should allow you to attach your function.For the selector something like this might be the best
You now just have to work out which date was selected.
解决方案
setTimeout-Wrapper 会在日历刷新后对内容进行排队。
Solution
The setTimeout-Wrapper will queue the stuff after the calendar got refreshed.