我有兩個日期,從日期和日期到,我的問題是,我希望從日期只能點擊/選擇過去的日期,直到當前的日期,然後日期可以自動選擇當前日期基於當前日期的日期驗證
下面的代碼
<!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