JQuery UI Datepicker, reverse the order of the year in the dropdowns

后端 未结 6 540
梦毁少年i
梦毁少年i 2020-12-01 16:58

I have a datepicker with changeyear: true. The \'year\' drop down displays the title as 2009, then instead of the next year below the title being 2008, 2007, 2006 and so on

6条回答
  •  难免孤独
    2020-12-01 17:00

    I think the best way to hack the plugin without ripping it is assigning a event handler to the year select item.

    //Hack for reverting year order
    $(document.body).delegate('select.ui-datepicker-year', 'mousedown', function() {
      (function(sel) {
        var el = $(sel);
        var ops = $(el).children().get();
        if ( ops.length > 0 && $(ops).first().val() < $(ops).last().val() ) {
          $(el).empty();
          $(el).html(ops.reverse());
        }
      })(this);
    });
    

    This code must work fine! :P

提交回复
热议问题