javascript - jQuery 日期选择器 minDate 未设置

标签 javascript jquery jquery-ui datepicker

我有两个日期选择器“startDate”和“targetDate”。我想将“targetDate”的minDate设置为“startDate”的值。以下 代码不起作用。即,未设置“targetDate”的 minDate。

$("#startDate").datepicker({
                changeMonth : true,
                changeYear : true,
                dateFormat : "dd-M-yy",
                minDate : 0,

                showMonthAfterYear : true,
                onClose : function() {

                    $(this).toggleClass('ui-state-focus');
                }
            });
            $("#targetDate").datepicker({
                changeMonth : true,
                changeYear : true,
                dateFormat : "dd-M-yy",
                minDate : new Date($("#startDate").val()),
                showMonthAfterYear : true,
                onClose : function() {
                    $(this).toggleClass('ui-state-focus');
                }

            });

最佳答案

您需要在onSelect中设置targetDate的最小日期startDate的事件

Called when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.

使用

$('#startDate').datepicker({
      onSelect: function(selectedDate) {
            $('#targetDate').datepicker('option', 'minDate', selectedDate);
      }
});

DEMO

关于javascript - jQuery 日期选择器 minDate 未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25377817/

相关文章:

javascript - 为什么我的 FOR 循环在这里不起作用?

asp.net - 如何将 jQuery UI 按钮图标添加到输入按钮?

javascript - 在 Google 评论脚本中将像素更改为百分比

javascript - 使用 JavaScript 和 python 实现网页浏览自动化

javascript - 将 json 数据从 servlet 传递到 jsp 再到 js 文件

jquery - 无法在 IE 中使用 jquery 获取背景图像值约为 :blank

javascript - PHP AJAX - &lt;input&gt; 元素可以像 <form> 一样具有 "action"吗?

javascript - 更改小数点分隔符

javascript - jQuery:尝试在页面加载时将函数 Hook 到 onclick

jquery - 如何使用多个互相连接的KendoListBox