jQuery Datepicker onClose 选择下一个
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15342360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Datepicker onClose select next
提问by Lee
I have a system where people can add multiple from and to dates ie screenshot:
我有一个系统,人们可以在其中添加多个起始日期和终止日期,即屏幕截图:
On selecting the first date the onClose event sets the date for second input and opens it. IE
在选择第一个日期时,onClose 事件设置第二个输入的日期并打开它。IE
datePickers = function() {
$(".from_date").datepicker({
minDate: 'D',
dateFormat: "dd/mm/yy",
defaultDate: "+1w",
numberOfMonths: 2,
onClose: function(selectedDate) {
$(".to_date").datepicker("option", "minDate", selectedDate);
return $(".to_date").datepicker("show");
}
});
return $(".to_date").datepicker({
minDate: '+1D',
dateFormat: "dd/mm/yy",
defaultDate: "+1w",
numberOfMonths: 2
});
};
My problem becomes when I have 2,3 or more and editing the first or second one.... On close it opens the last input.
当我有 2,3 个或更多并编辑第一个或第二个时,我的问题就变成了......关闭时它会打开最后一个输入。
I have tried using .next('to_date') and closest('to_date') but its not working.
我试过使用 .next('to_date') 和最近的('to_date') 但它不起作用。
Any advise on how I can get around this.
关于我如何解决这个问题的任何建议。
As requested a fiddle: http://jsfiddle.net/FdfPY/
根据要求小提琴:http: //jsfiddle.net/FdfPY/
回答by Dom
Rather than using return $(".to_date").datepicker("show");
, do the following:
而不是使用return $(".to_date").datepicker("show");
,请执行以下操作:
$(".from_date").datepicker({
minDate: 'D',
dateFormat: "dd/mm/yy",
defaultDate: "+1w",
numberOfMonths: 2,
onClose: function(selectedDate) {
$(".to_date").datepicker("option", "minDate", selectedDate);
$(this).parent().next().children().focus();
}
});
$(".to_date").datepicker({
minDate: '+1D',
dateFormat: "dd/mm/yy",
defaultDate: "+1w",
numberOfMonths: 2
});
DEMO: http://jsfiddle.net/FdfPY/1/
演示:http: //jsfiddle.net/FdfPY/1/
EDIT:
编辑:
If it is nested, then use the following:
如果它是嵌套的,则使用以下内容:
$(".from_date").datepicker({
minDate: 'D',
dateFormat: "dd/mm/yy",
defaultDate: "+1w",
numberOfMonths: 2,
onClose: function(selectedDate) {
$(".to_date").datepicker("option", "minDate", selectedDate);
$(this).parents('.span2').next().children().find('.to_date').focus();
}
});
$(".to_date").datepicker({
minDate: '+1D',
dateFormat: "dd/mm/yy",
defaultDate: "+1w",
numberOfMonths: 2
});