【发布时间】:2011-06-10 07:46:35
【问题描述】:
我需要在我的输入元素中添加一个“上方”或“下方”类,具体取决于日期选择器在哪一侧打开。
我似乎无法弄清楚如何获得即将创建的日期选择器实例的位置....也许我只是想错了。
$('#order-main .datepicker').datepicker({
showOn: 'both',
buttonImage: 'img/icons/calendar.png',
buttonImageOnly: true,
minDate: -1,
maxDate: "+1Y",
showButtonPanel: true,
showAnim: 'slideDown',
hideIfNoPrevNext: true,
dateFormat: 'yyyy-mm-dd',
duration: 500,
beforeShow: function(input, inst) {
var pos = $(input).offset().top;
// if the top position of the to-be-created instance is < top position
//of the elemnt, its ABOVE, therefore add above, otherwise add below.
inst.dpDiv.addClass('above')
}
});
我知道如何使用 $.extend($.datepicker,{_checkOffset:function(inst,offset,isFixed){return offset}});所以它总是显示在下面,但我更愿意保留它的动态放置功能,但只知道它是在上面还是在下面,这样我就可以正确地设置我的输入元素的样式。
小事一桩,完成就好了。
【问题讨论】:
标签: jquery jquery-ui datepicker