gpt4 book ai didi

jquery - 动态设置 ui datepicker max/minDate

转载 作者:行者123 更新时间:2023-12-01 03:26:01 25 4
gpt4 key购买 nike

以为这会比实际更容易。任务:

1) 禁用 future 日子。 (将 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() 仅在第一次按下按钮时起作用。

最佳答案

我在 this site 上找到了可能的答案

显然您使用选项值来执行此操作:

 $("#datepicker").datepicker('option', 'minDate', newDate); 

关于jquery - 动态设置 ui datepicker max/minDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5117282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com