我有两个名为LeaveFrom& amp;的文本框LeaveTo.In(Leavefrom)文本框我想通过JQuery datepicker设置日期,但是在(Leaveto)文本框中我想通过禁用next& amp;选择仅由(Leavefrom)文本框选择的那个月的日期。上个月&从选定的日期开始。
<script type="text/javascript">
$(document).ready(function() {
$('#txtDate').datepicker({
showAnim: 'slide',
dateFormat: 'dd-mm-yy',
});
$("#txtToDate").datepicker({
minDate: 0,
maxDate: "+60D",
numberOfMonths: 2,
onSelect: function (selected) {
$("#txtFromDate").datepicker("option", "maxDate", selected)
}
});
});
</script>
答案 0 :(得分:0)
$(document).ready(function () {
var d = new Date();
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
today = monthNames[d.getMonth()] + ' ' + d.getDate() + ' ' + d.getFullYear();
$('#to').attr('disabled', 'disabled');
$('#from').datepicker({
defaultDate: "+1d",
minDate: 0,
maxDate: "+2M",
dateFormat: 'dd-mm-yy',
required: true,
showOn: "focus",
});
$('#from').change(function () {
var from = $('#from').datepicker('getDate');
var date_diff = Math.ceil((from.getTime() - Date.parse(today)) / 86400000);
date_diff = date_diff + 'd';
$('#to').val('').removeAttr('disabled').removeClass('hasDatepicker').datepicker({
dateFormat: 'dd.mm.yy',
minDate: date_diff,
changeMonth: false,
hideIfNoPrevNext: true,
stepMonths: 0,
});
});
});
在var today
今天的日期以格式August 14 2013
from
的输入被指定了日期选择器,日期显示明天到下个月3个月
标识to
的输入将被禁用,直到用户选择ID为from
在ID为from
的输入中更改日期时,var date_diff
计算当前日期与输入中选择的日期之间的差异from
和变量{{1传递给ID为date_diff
的输入中的minDate
选项,并且已启用。
to
禁用月份更改,因此用户只能在该月内选择日期。