根据javascript或jquery中的选定日期来禁用datepicker的先前日期
问题描述:
我有两个datepickers如startdate和enddate.If我选择2015年6月18日在startdate我必须禁用datepicker以前的日期到18thjune2015在enddate。
I have two datepickers like startdate and enddate.If i select 18th june 2015 in startdate i have to disable previous dates in datepicker to 18thjune2015 in enddate.
这里是我的代码。
$("#txtstartdate").datepicker({ minDate: 0 });
对于结束日期:
var startdate = $("#txtstartdate").val();
$("#txtenddate").datepicker({ minDate: startdate });
它不工作。任何人都可以帮助我。
谢谢。
Its not working. Can anyone pls help me on this. thank you.
答
您需要使用选项方法在更改开始日期时设置
You need to set it using the option method on change of start date
$("#txtstartdate").datepicker({
minDate: 0,
onSelect: function(date) {
$("#txtenddate").datepicker('option', 'minDate', date);
}
});
$("#txtenddate").datepicker({});
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/redmond/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.js"></script>
<input id="txtstartdate" />
<input id="txtenddate" />