我有两个日期,从日期和日期到,我的问题是,我希望从日期只能点击/选择过去的日期,直到当前的日期,然后日期可以自动选择当前日期基于当前日期的日期验证
下面的代码
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$("#from").datepicker({
dateFormat: 'yy-mm-dd',
defaultDate: "+1 \t w",
changeMonth: true,
\t changeYear: true,
numberOfMonths: 1,
yearRange: '2006:'+(new Date).getFullYear() ,
onClose: function(selectedDate) {
$("#to").datepicker("option", "minDate", selectedDate);
}
});
$("#to").datepicker({
dateFormat: 'yy-mm-dd',
defaultDate: "+1w",
changeMonth: true,
\t changeYear: true,
numberOfMonths: 1,
yearRange: '2006:'+(new Date).getFullYear() ,
onClose: function(selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
</script>
</head>
<body>
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
</body>
</html>
可能重复的[发布](http://stackoverflow.com/questions/14810602/how-to-set-mindate-to-current-date-in -jquery-UI-日期选择器)。 – Rajesh
我试过了,它不起作用:( – Vista
,它也不同 – Vista