我有两个日期选择器(jqueryui),我想将第二个输入(minDate属性)限制为首先选择的值。我该怎么做?我写了下面的代码,没有成功:
$("#picker1").button().click(function() {
var minDate = $( "#picker1" ).datepicker( "getDate" );
$( "#picker2" ).datepicker( "option", "minDate", minDate );
$( "#picker2" ).datepicker( "refresh");
});
你能帮我解决这个问题吗?
谢谢!
答案 0 :(得分:9)
尝试
$('#p1, #p2').datepicker();
$('#p1').change(function(){
$('#p2').datepicker('option', 'minDate', $('#p1').datepicker('getDate'))
});
演示:Fiddle
答案 1 :(得分:1)
几天后,对我来说,有什么工作要做:
$("#picker1").datepicker({
onClose: function(selectedDate){
$("#picker2").datepicker("option", "minDate",selectedDate);
}
});
中检索
答案直到此日期无效。来自@Arun的回答P Johny在Fiddle工作得很好,但在我的系统中没有(我不知道为什么)。
答案 2 :(得分:0)
我怀疑getDate
返回字符串。你可以这样试试。
$("#picker1").button().click(function() {
var minDate = $( "#picker1" ).datepicker( "getDate" );
$( "#picker2" ).datepicker( "option", "minDate", new Date(minDate));
$( "#picker2" ).datepicker( "refresh");
});