Jquery 动态设置ui datepicker max/minDate
我想这比现在容易多了。 任务: 1) 禁用未来日期。(将maxDate设置为今天-完成) 2) 从js变量获取日期,并将其设置为动态的minDate-如何? 主要功能(我只使用了几页): 然后是我现在要编辑的页面的js代码:Jquery 动态设置ui datepicker max/minDate,jquery,user-interface,datepicker,maxdate,mindate,Jquery,User Interface,Datepicker,Maxdate,Mindate,我想这比现在容易多了。 任务: 1) 禁用未来日期。(将maxDate设置为今天-完成) 2) 从js变量获取日期,并将其设置为动态的minDate-如何? 主要功能(我只使用了几页): 然后是我现在要编辑的页面的js代码: function calendarMaxDate(){//disable future days var date = new Date(); var currentMonth = date.getMonth(); var currentDate = date.getDa
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()只在第一次按下按钮时才起作用。我在上找到了一个可能的答案 显然,您使用选项值来执行此操作:
$("#datepicker").datepicker('option', 'minDate', newDate);
这是什么类型的项目?例如ASP.NET或MVC?MinDate中加载子初始化事件的奇怪方式。那么它应该是什么呢?@Luke Duddridge——它只是PHP/Javascript/Ajax/HTML/sqlmix;)@aavezel你说的是‘函数($){}’?我对jquery很陌生,我正在做一些我不能做的事情。只是删除了'function($){…}',至少现在每当按下按钮时,函数都会提醒值-现在,唯一剩下的问题是datepicker在函数被调用后并没有改变minDate值。问题仍然并没有解决——现在我已经做了另一个选择,它可以工作,但看起来不太好。谢谢大家的评论。无论如何,如果有人能提供一个适合这个问题的解决方案,我很乐意看到。正如OP的代码所示,他已经在尝试设置这个选项,并表示它不起作用。
$("#datepicker").datepicker('option', 'minDate', newDate);