本文介绍了如何在其他Datepicker的Datepicker中设置Min Date?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在向我的日期选择器添加验证,并且无法将日期选择器中的最小日期设置为在日期选择器中选择的任何内容。如果选择了12-3-15,则截止日期选择器的最小日期为12-3-15。这是我使用的代码:

I am currently adding validation to my date pickers and am having trouble setting the min date in the to date picker to be whatever was chosen in the from date picker. I.e if 12-3-15 is selected then the minimum date in the to date picker is 12-3-15. Here is the code I am using:

$("#from").datepicker({
            defaultDate: new Date(),
            minDate: new Date(),
            onSelect: function(dateStr)
            {
            fromDate = new Date(dateStr);
            }
        });

$('#to').datepicker({
            defaultDate: new Date(),
            minDate: ("#from" + "1D"), (<- HERE)
            onSelect: function(dateStr) {
            toDate = new Date(dateStr);

                // Converts date objects to appropriate strings
                fromDate = ConvertDateToShortDateString(fromDate);
                toDate = ConvertDateToShortDateString(toDate);
        });

有人知道我能如何实现吗?

Does anybody know how I could achieve this?

推荐答案

请检查这个工作小提琴

使用选项设置 minDate 到第二个 datepicker

$("#from").datepicker({
        defaultDate: new Date(),
        minDate: new Date(),
        onSelect: function(dateStr)
        {
            $("#to").val(dateStr);
            $("#to").datepicker("option",{ minDate: new Date(dateStr)})
        }
    });

这篇关于如何在其他Datepicker的Datepicker中设置Min Date?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:10