我正在使用jquery DatePicker。我有一个下拉列表,我需要根据下拉列表重置DatePicker的minDate选项。这是代码段。
HTML
<input id="Date_From" name="Date_From">
<select id="Select" >
<option value="Choice1">Choice1</option>
<option value="Choice2">Choice2</option>
<select>
JS
$("#Date_From").datepicker();
$("#Date_To").datepicker();
$('#Select').change(function () {
var option = this.value;
if (option == 'Choice1')
{
$( "#Date_From" ).datepicker( "option", "minDate", new Date(2015, 1 - 1, 1) );
}
else if (option == 'Choice2')
{
$( "#Date_From" ).datepicker( "option", "minDate", new Date(2015, 1 - 7, 1) );
}
else{
}
});
答案 0 :(得分:1)
问题出在月份计算中,您需要为7-1
01 Jul 2015
(6)
$("#Date_From").datepicker();
$("#Date_To").datepicker();
$('#Select').change(function() {
var option = this.value;
if (option == 'Choice1') {
$("#Date_From").datepicker("option", "minDate", new Date(2015, 1 - 1, 1));
} else if (option == 'Choice2') {
$("#Date_From").datepicker("option", "minDate", new Date(2015, 7 - 1, 1));
}
}).change();
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.css" rel="stylesheet" />
<input id="Date_From" name="Date_From" />
<select id="Select">
<option value="Choice1">Choice1</option>
<option value="Choice2">Choice2</option>
</select>
&#13;