jQuery Datepicker on关闭选择下一步 [英] jQuery Datepicker onClose select next

查看:200
本文介绍了jQuery Datepicker on关闭选择下一步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个系统,人们可以在其中添加多个日期,例如:屏幕截图:

I have a system where people can add multiple from and to dates ie screenshot:

在选择第一个日期时,onClose事件设置第二个输入的日期并打开它. IE浏览器

On selecting the first date the onClose event sets the date for second input and opens it. 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
    });
  };

当我有2,3个或更多并且编辑第一个或第二个...时,我的问题就变成了.关闭时,它将打开最后一个输入.

My problem becomes when I have 2,3 or more and editing the first or second one.... On close it opens the last input.

我尝试使用.next('to_date')和最近的('to_date'),但无法正常工作.

I have tried using .next('to_date') and closest('to_date') but its not working.

任何有关如何解决此问题的建议.

Any advise on how I can get around this.

根据要求提供小提琴: http://jsfiddle.net/FdfPY/

As requested a fiddle: http://jsfiddle.net/FdfPY/

推荐答案

而不是使用return $(".to_date").datepicker("show");,请执行以下操作:

Rather than using return $(".to_date").datepicker("show");, do 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).parent().next().children().focus();
      }
    });
 $(".to_date").datepicker({
      minDate: '+1D',
      dateFormat: "dd/mm/yy",
      defaultDate: "+1w",
      numberOfMonths: 2
    });

演示: http://jsfiddle.net/FdfPY/1/

如果是嵌套的,则使用以下内容:

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
    });

演示: http://jsfiddle.net/FdfPY/5/

这篇关于jQuery Datepicker on关闭选择下一步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆