jQuery DatePicker:防止"Today"按钮从变灰 [英] jQuery DatePicker: Prevent the "Today" button from being grayed out

查看:180
本文介绍了jQuery DatePicker:防止"Today"按钮从变灰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与帖子 jQuery UI Datepicker Today链接

使用下面的代码将以黑色显示今日"按钮.但是,它只能运行一次,因为单击今日"按钮后,它又变回了灰色.有没有更好的方法来处理此问题,以使色彩渲染永久不变?

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');
  });
});

更新: https://jsfiddle.net/megoo1xk/14/

推荐答案

因为datepicker仅具有beforeShow事件,而不是onShow,onOpen或afterShow.我们应该自己建造它.

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));
  }

参考: jquery datepicker上的afterShow事件

如果我们加入您的功能,它将类似于此小提琴

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

这篇关于jQuery DatePicker:防止"Today"按钮从变灰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆