jQuery 日期选择器 Mindate、MaxDate
我有以下两个日期选择器对象,但我无法得到我想要的,因为我陷入了 minDate 和 maxDate 选项:
这是将日期限制为未来的日期。
我什么想要:将日期限制为从当前日期到 30 年时间。
我得到的:将日期限制为从当前日期到 10 年时间。
$(".datepickerFuture").datepicker({
showOn: "button",
buttonImage: 'calendar.gif',
buttonText: 'Click to select a date',
duration:"fast",
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
constrainInput: true,
minDate: 0,
maxDate: '+30Y',
buttonImageOnly: true
});
这是限制只选择过去的日期:
我想要的:限制日期从当前日期到120年前的时间。
我得到的:将日期限制为从当前日期到 120 年前的时间,但是当我选择年份时,最大年份将重置为所选年份(例如,当页面从新鲜状态加载时我会得到的是 1890 -2010,但如果我选择 2000,年份选择框将重置为 1880-2000) 。
$(".datepickerPast").datepicker({
showOn: "button",
buttonImage: 'calendar.gif',
buttonText: 'Click to select a date',
duration:"fast",
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
constrainInput: true,
yearRange: '-120:0',
maxDate: 0,
buttonImageOnly: true
});
我需要有关日期选择器对象的帮助,任何帮助将不胜感激。
I have the two following datepicker objects but I can't get what I want as I am getting stuck with the minDate and maxDate options:
This is to restrict the dates to future dates.
What I want: restrict the dates from current date to 30 years time.
What I get: restrict the dates from current date to 10 years time.
$(".datepickerFuture").datepicker({
showOn: "button",
buttonImage: 'calendar.gif',
buttonText: 'Click to select a date',
duration:"fast",
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
constrainInput: true,
minDate: 0,
maxDate: '+30Y',
buttonImageOnly: true
});
This is to restrict to select only past dates:
What I want: restrict the dates from current date to 120 years ago time.
What I get: restrict the dates from current date to 120 years ago time, but when I select a year the maximum year will reset to selected year (e.g. what I would get when page load from fresh is 1890-2010, but if I select 2000 the year select box reset to 1880-2000) .
$(".datepickerPast").datepicker({
showOn: "button",
buttonImage: 'calendar.gif',
buttonText: 'Click to select a date',
duration:"fast",
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
constrainInput: true,
yearRange: '-120:0',
maxDate: 0,
buttonImageOnly: true
});
I need help with both datepicker object, any help would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我解决了 jquery 库有点过时的问题。
如果有人对此解决方案感兴趣,请查看此处。
I fixed my problem which it was the jquery libraries were a bit out date.
If anyone interested on this solution please check here.
+30 年应该可以正常工作,如此处所示:
对于-120 年,您只需执行以下操作反此处
The +30 years one should work fine as shown here:
For -120 years you just need to do the inverse here
显示从当前日期到 1 年 = maxDate: '+1Y',
显示从当前日期到 30 天 = maxDate: '+30D',
To display from current date to 1 year = maxDate: '+1Y',
To display from current date to 30 days = maxDate: '+30D',