0

我有一个 jquery datepicker,其中只有某些日期在日历中是可分割的。按钮栏上的今天按钮的功能已被覆盖以在字段中填充今天的日期。现在,如果今天不是用户选择的有效日期,我正在尝试禁用按钮栏上的今天按钮。我试图通过将 ui-datepicker-current 类更改为包含 ui-state-disabled 而不是 ui-state-default 来做到这一点。不过,我似乎无法更改课程。我尝试在 beforeShow 中添加逻辑:

$(document).ready( function() {
  $( ".MyForm-date" ).datepicker( {
    changeYear: true,
    dateFormat: "dd M yy",
    yearRange: "-20:+10",
    showButtonPanel: true,
    beforeShow : function( input, instance ) { 
        instance.dpDiv.find(".ui-datepicker-current").removeClass("ui-state-default").addClass("ui-state-disabled");
        return initGoodReportDates( input, instance ); },
    onChangeMonthYear : function( year, month, instance ) { return  refreshGoodReportDates(year, month, instance); },
    beforeShowDay : function( date ) { return isGoodReportDate( date ); },
    onClose : function(){ checkDate( this ); }
  });

以及在此块下方添加逻辑:

$(document).ready( function() {
  $( ".MyForm-date" ).datepicker( {
    changeYear: true,
    dateFormat: "dd M yy",
    yearRange: "-20:+10",
    showButtonPanel: true,
    beforeShow : function( input, instance ) { 
        return initGoodReportDates( input, instance ); },
    onChangeMonthYear : function( year, month, instance ) { return refreshGoodReportDates(year, month, instance); },
    beforeShowDay : function( date ) { return isGoodReportDate( date ); },
    onClose : function(){ checkDate( this ); }
  });

$(".MyForm-date").datepicker("widget").find("ui-datepicker-current").removeClass("ui-state-default").addClass("ui-state-disabled");

但是,两者都没有更改与 ui-datepicker-current 按钮关联的类。谁能告诉我如何访问该按钮?

谢谢

4

1 回答 1

0

在执行 beforeShow 之后使用超时来修改按钮:

    $('.foo').datepicker({
        beforeShow: function(input, inst) {
            setTimeout(function() { 
              //...
            }, 0);   
        }
    })

在此处查看示例

您还必须处理onChangeMonthYear事件。

于 2018-02-01T01:10:25.427 回答