我想要两个日期选择器 1-fromDate 和 2-toDate 如果我在 fromDate 中选择月/任何日期/年,则 toDate 日期选择器设置为下个月/任何日期/年并禁用以前的日期。
$("#fromDate").datepicker({
maxDate: 0,
onSelect: function (date) {
$("#toDate").datepicker('option', 'minDate', date);
}
});
$("#toDate").datepicker({
maxDate: '0'
});
此代码禁用的是日期而不是月份
最佳答案
试试这个
$( function()
{
var dateFormat = "mm/dd/yy",
from = $( "#from" )
.datepicker
({
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function()
{
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#to" ).datepicker({
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function()
{
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element )
{
var date;
try
{
date = $.datepicker.parseDate( dateFormat, element.value );
}
catch( error )
{
date = null;
}
return date;
}
} );
关于javascript - 如何禁用日期选择器中先前选定的月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38688774/