开发者

Why arrows in jQuery UI Datepicker make wrong change of the date?

开发者 https://www.devze.com 2023-03-20 09:17 出处:网络
I am having standard jQuery UI datepicker like this: $(\'.text_input\').live(\'focus\', function () { $(this).datepicker(\'destroy\').datepicker({dateFormat: \'dd.mm.yy\'});

I am having standard jQuery UI datepicker like this:

$('.text_input').live('focus', function () {
  $(this).datepicker('destroy').datepicker({dateFormat: 'dd.mm.yy'});
});

In the input is already date, e.g. 14.7.2010. When I click the input, datepi开发者_运维知识库cker appears and it shows selected date filled in input. However, when I try to navigate using left and right arrows at the top of the datepicker, strange thing happens - it changes date in datepicker to November 1899 or January 1900, depending which arrow I click.

Anybody has any idea why is this happening ? And how to fix it ? I am using jQuery UI 1.8.14 and jQuery 1.4.2.


Don't destroy it. :)

$('.text_input').live('focus', function() {
    $(this).datepicker({
        dateFormat: 'dd.mm.yy'
    });
});


You don't need to initialize/create/assing datepicker every time an input gets focus. You can just assign it when dom is ready.

$(document).ready(function(){
    $('.text_input').datepicker({ dateFormat: 'dd.mm.yy' });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号