$('#toDate').change(function () {
selectedToDate = $('#toDate').val();
var year = selectedToDate.substring(6, 10);
var day = selectedToDate.substring(3, 5);
var month = selectedToDate.substring(0, 2);
$('#fromDate').datepicker({
minDate: new Date(year, month-1, day),
inline: true
});
});
我试图禁用日历的过去日期。但我的代码不起作用。
答案 0 :(得分:1)
请尝试使用$( "#fromDate" ).datepicker( "option", "minDate", new Date(year, month-1, day) );
$('#toDate').change(function () {
selectedToDate = $('#toDate').val();
var year = selectedToDate.substring(6, 10);
var day = selectedToDate.substring(3, 5);
var month = selectedToDate.substring(0, 2);
$( "#fromDate" ).datepicker( "option", "minDate", new Date(year, month-1, day) );
/*$('#fromDate').datepicker({
minDate: new Date(2017, 3, 15),
inline: true
});*/
})

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#toDate" ).datepicker();
$( "#fromDate" ).datepicker();
} );
</script>
<p>Date: <input type="text" id="toDate"></p>
<p>To:<input type="text" id="fromDate"></p>
&#13;
答案 1 :(得分:0)
$('#datepicker').datepicker({ minDate: 0 });
&#13;
body {
font-size: 12px; /* just so that it doesn't default to 16px (which is kinda huge) */
}
&#13;
<!-- load jQuery and jQuery UI -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- load jQuery UI CSS theme -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<!-- the datepicker input -->
<input type='text' id='datepicker' placeholder='Select date' />
&#13;