2

认为它会比它更容易。任务:

1)禁用未来的日子。(将 maxDate 设置为今天 - 完成)

2)从js变量获取日期并将其设置为即时的minDate -如何?

主要功能(我用了几页):

jQuery(
    function($){
        $('#datepicker').datepicker({
             onSelect: function(dateText, inst){calendarOptions(dateText);},
            // beforeShow: function() {$("#datepicker").datepicker( "option", "minDate", curdate ).next('button').text('Kalendārs').button({icons:{primary : 'ui-icon-plus'}})}, 
             showOn: "button",
             dateFormat: 'dd.mm.yy',
             prevText: '«',
             nextText: '»',
             monthNames: ['Janvāris','Februāris','Marts','Aprīlis','Maijs','Jūnijs', 'Jūlijs','Augusts','Septembris','Oktobris','Novembris','Decembris'],
             monthNamesShort: ['JAN', 'FEB', 'MAR', 'APR', 'MAI', 'JUN', 'JUL', 'AUG', 'SEP', 'OKT', 'NOV', 'DEC'],
             dayNamesMin: ['S', 'P','O','T','C','P','S'],
             firstDay: 1,
             maxDate: calendarMaxDate()
        }).next('button').text('Kalendārs').button({icons:{primary : 'ui-icon-plus'}});
    }

);

然后是我现在要编辑的页面的 js 代码:

function calendarMaxDate(){//disable future days
var date = new Date(); 
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
return new Date(currentYear, currentMonth, currentDate)
//return null; // set to default
}

function calendarOptions(dateText){ // sets selected date to 'external' input field
autofield_date.setValue(dateText);
}

jQuery(
    function($){ // calls function before ui datepicker button is pressed
        $('.ui-datepicker-trigger').click(function() {
        alert(autofield_dekl.getValue());
            MinDate();
        });
    }
);

function MinDate(){ //pass curdate value as'minDate' to calendar on the fly

    jQuery( //not sure about this part
        function($){ //without onload function it throws an error: $("#datepicker") is null
            $("#datepicker").datepicker( "option", "minDate", curdate ).next('button').text('Kalendārs').button({icons:{primary : 'ui-icon-plus'}})//;
        }
    )
    alert(curdate);
}

函数 MinDate() 仅在第一次按下按钮时起作用。

4

1 回答 1

4

我在这个网站上找到了一个可能的答案

显然你使用选项值这样做:

 $("#datepicker").datepicker('option', 'minDate', newDate); 
于 2011-08-11T18:55:07.427 回答