[英]With 2 dates I need to block the datepicker option for 2nd date based on 1st date selection
I have two datepicker fromdate and todate. 我有两个datepicker fromdate和todate。 Based on fromdate selection, I need to block the dates above the fromdate in the second datepicker(toDate).
基于fromdate选择,我需要在第二个datepicker(toDate)中阻止fromdate以上的日期。
eg 例如
fromdate: 17/6/2013 (MM/DD/YYYY)
todate: selection should be available from 17/6/2013. any date above 17/6/2013 should be disabled.
How do I achieve this? 我该如何实现?
Assuming you're using jQuery UI's datepicker, I think you're looking for Date range. 假设您正在使用jQuery UI的datepicker,我想您正在寻找的是Date范围。 You'd have a markup like this :
您会有这样的标记:
<label for="from">From</label>
<input type="text" id="from" name="from" />
<label for="to">to</label>
<input type="text" id="to" name="to" />
Then, in the JS, 然后,在JS中
$(function() {
$( "#from" ).datepicker({
//not needed
defaultDate: "+1w",
//to show the month dropdown
changeMonth: true,
//the number of months to be shown when input is focussed
numberOfMonths: 1,
//**Important!**
onClose: function( selectedDate ) {
//dynamically set min-date of second datepicker to selected date in the first datepicker
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
//dynamically set max-date property of #from text box
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
Docs : http://jqueryui.com/datepicker/#date-range 文件: http : //jqueryui.com/datepicker/#date-range
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.