[英]jQuery date picker - Disable dates after the selection from the first date picker
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</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 () {
$("#datepicker1").datepicker();
});
</script>
<script>
$(function () {
$("#datepicker2").datepicker();
});
</script>
</head>
<body>
<p>Date 1: <input type="text" id="datepicker1"></p>
<p>Date 2: <input type="text" id="datepicker2"></p>
</body>
</html>
There are two date pickers in my code here. 我的代码中有两个日期选择器。 What I want is to disable dates when I select a date from the first date picker.
我要从第一个日期选择器中选择一个日期时禁用日期。 That is suppose if I select date like
15/01/2015
from the first date picker. 那是假设我从第一个日期选择器中选择了2015年1月
15/01/2015
日这样的日期。 Now in the second date picker all the dates after 15/01/2015
will be disabled. 现在,在第二个日期选择器中,2015年1月
15/01/2015
日之后的所有日期都将被禁用。 But the dates before 15/01/2015
will be enabled in the second date picker. 但是,第二个日期选择器将启用2015年1月
15/01/2015
日之前的日期。
How can I do that? 我怎样才能做到这一点?
onSelect
event fires when you select a date from DatePicker. 从DatePicker中选择日期时,将
onSelect
事件。
Try the following code. 请尝试以下代码。
$(function () {
$("#datepicker1").datepicker({
onSelect: function (date) {
$("#datepicker2").datepicker({
'maxDate': date
//'minDate' : date
});
}
});
});
You can manipulate the dates using maxDate and minDate properties. 您可以使用maxDate和minDate属性操作日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.