问题描述
这似乎是一件简单的事情,但我无法解决它,我真的需要这个。 如何通过SelectedDate事件添加日期到选定的日期?
It seems a simple thing but i'm unable to solve it and i really need this. How can i add a date to a selected date, through the SelectedDate event?
我需要对2个日期检查器执行日期范围限制。一旦用户设置了一个datepicker,其他需要只允许日期等于第一个datepicker的选定日期,加上一个月。
I need to perform a date range limit on 2 datepickers. Once the user set one datepicker the other needs to only allow date equals to the selected date of the first datepicker, plus one month.
示例:如果我在第一个日历上设置'3 of march',则第二个日历必须只允许大于4的日期。
Example: if i set '3 of march' on the first calendar, the second must allow only dates greater than '3 of april'.
到目前为止,我只能得到相同的选择日期,或者通过 $('#dtpicker')设置的日期datepicker(setDate,+ 1m ');
。我尝试了jquery-ui文档示例,但没有。
So far by now i can only get the same selected date or the one i set through $('#dtpicker').datepicker( "setDate" , '+1m');
. I tried the jquery-ui documentation example, but nothing.
推荐答案
我已经在两个日期提示器上实现了类似的功能。
I have implemented similar functionality on two datepickers.
function handleDateChange() {
var dateStart = $('#datepicker-startdate').datepicker("getDate"),
dateEnd = $('#datepicker-enddate').datepicker("getDate");
if (dateStart !== null) {
dateStart.setDate(dateStart.getDate() + 1);
$('#datepicker-enddate').datepicker('option', 'minDate', dateStart);
}
if (dateEnd !== null) {
dateEnd.setDate(dateEnd.getDate() - 1);
$('#datepicker-enddate').datepicker('option', 'maxDate', dateEnd);
}
}
在 onSelect
datepickers的处理程序(作为init选项):
Use this method in the onSelect
handler of your datepickers (as init option):
$(/*your datepicker selector*/).datepicker({
// ... other init options
onSelect : function(dateText, inst) {handleDateChange();}
});
我认为这与你需要的相似,如果不是,那肯定会让你在右边轨道。
I think this is similar to what you need, if not then it should definitely get you on the right track.
这篇关于jquery UI - 将日期添加到选定的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!