jQuery DatePicker: Prevent the “Today” button from being grayed out

耗尽温柔 提交于 2020-01-06 06:14:08

问题


This is related to post jQuery UI Datepicker Today Link

Using the code below results in the "Today" button being rendered in black. However, it only works once because when the "Today" button is clicked it goes back to being grayed out. Is there a better way to handle this so that the color rendering is permanent?

$(document).ready(function() {
  $(".datePicker").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
    yearRange: "2000:c+1",
    showButtonPanel: true
  });

 $('.datePicker').click(function () {
        $('button.ui-datepicker-current').removeClass('ui-priority-secondary').addClass('ui-priority-primary');
  });
});

Update: https://jsfiddle.net/megoo1xk/14/


回答1:


since datepicker only have beforeShow event instead onShow, onOpen or afterShow. We should build it by ourself.

$.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker;
  $.datepicker._updateDatepicker = function(inst) {
    $.datepicker._updateDatepicker_original(inst);
    var afterShow = this._get(inst, 'afterShow');
    if (afterShow)
      afterShow.apply((inst.input ? inst.input[0] : null));
  }

Reference: afterShow event on jquery datepicker

if we join with your function, that will be like this fiddle



来源:https://stackoverflow.com/questions/49164670/jquery-datepicker-prevent-the-today-button-from-being-grayed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!