jQuery Datepicker - 根据之前的日历限制 minDate
我有 2 个日期选择器,如下所示:
$(function() {
$( "#datepicker1, #datepicker2" ).datepicker({
minDate: 'today',
maxDate: "+90D",
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
dateFormat: "D, dd MM, yy"
});
});
我希望 datepicker2
在第一个日历 + 1 天中选择最小日期值。(即,如果第一个日历日期是 5 月 16 日,第二个日历应将最小日期设置为 5 月17日)
I have 2 datepickers as following:
$(function() {
$( "#datepicker1, #datepicker2" ).datepicker({
minDate: 'today',
maxDate: "+90D",
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
dateFormat: "D, dd MM, yy"
});
});
I want datepicker2
have the minimumdate value selected in the first calendar + 1 day.(i.e. if first calendar date was May 16th, 2nd calendar should have the min date set to May 17th)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我也有同样的情况。我所做的是在第一个日期选择器的“select”事件处理程序中设置第二个日期选择器的 minDate 值。工作起来就像一个魅力。
编辑:这是一个例子:
I had the same scenario. What I did was to set the minDate value of the second datepicker in the "select" event handler of the first datepicker. Worked like a charm.
EDIT: Here is an example:
这里的详细答案并没有真正回答这个问题,即“如何根据第一个日期选择器的值设置第二个日期选择器的 minDate + 1 DAY”?
对你来说可能已经太晚了,但由于我很难找到解决方案,这里是:
说明:
你必须从 datepicker1 字段获取一个包含年、月、日的日期对象。
然后,调用此 Date 对象并将其转换为 UNIX 时间戳,并在其中添加 86400000(一天的微秒数)。这会给你一个新的 Date 对象。
之后,通过调用 jQuery DatePicker API 的
formatDate
方法,将刚刚创建的 Date 对象格式化为正确的显示(可能不是本答案中提供的显示)。最后,将 datepicker2 字段的 minDate 与 new_date 一起应用。
Detailed answers here don't really answer the question, which was "how do I set the minDate of the second datepicker, on the value of the first datepicker + 1 DAY" ?
It might be too late for you but since I quite struggled to find a solution, here it is :
Explanations :
You have to get a Date object from the datepicker1 field, with Year, Month, Day.
Then, you call this Date object and transform it into a UNIX Timestamp, to which you add 86400000 (number of microseconds in one day). Which gives you a new Date object.
After that, you format the Date object you just created to the correct display (which may not be the one presented in this answer), by calling
formatDate
method of jQuery DatePicker API.In the end, you apply the minDate of your datepicker2 field with your new_date.
看一下范围示例: http://jqueryui.com/demos/datepicker/#date -范围
Have a look at the range example: http://jqueryui.com/demos/datepicker/#date-range
我推荐 Filament Group 的 DateRange Picker: http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework /
我过去曾使用过它,并且设置起来很容易。
I'd recommend the DateRange Picker from Filament Group: http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/
I've used it in the past and it's a breeze to set up.
这是另一个解决方案。在这种情况下,我使用“日期从”和“日期到”作为日期选择器中的默认文本。
Here is another solution. In this context I am using "Date From" and "Date To" as default text in datepicker.
您必须初始化两个日期选择器。
You must initialize both datepicker.
试试这个:对我来说效果很好
希望会有帮助。
谢谢。
Try this : works fine for me
Hope will be Helpful.
Thanks.