jquery datepicker minDate 当前月份的特定日期
H
我需要自定义两个日期选择器。
首先应该有:
- minDate:本月的最后十天(或者如果更简单:本月20日)
- maxDate:下个月的10日
我只能按照“手册”中给出的方式进行设置,如下所示:+1m +2w +5d。但这对我来说并不好,因为我不需要相对于当前数据。
有什么想法吗?
我试过了,但没有成功:
// temp vars used below
var currentTime = new Date()
// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
dateFormat: 'dd.mm.yy',
// minDate: '+10d',
minDate: new Date(currentTime.getYear(), currentTime.getMonth(), 20),
maxDate: '+3w'
});
BR。安德斯
更新 - 解决方案 我使用了殡仪馆的答案,效果很好。感谢您的回答:-)
// temp vars used below
var currentTime = new Date();
var startDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -10); // 10 days before next month
var startDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -1); // one day before next month
var endDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 3); // 3rd of next month
var endDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 10); // 10th of next month
// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
dateFormat: 'dd.mm.yy',
minDate: startDateFrom,
maxDate: startDateTo
});
H
I need to customize two datepickers.
First shold have:
- minDate: last ten days of this month (or if easier: 20th of this month)
- maxDate: 10th of next month
I can only set then as given in "manual" like this: +1m +2w +5d. But that is not good in my case since I do not need to go relative to current data.
Any idea?
I have tried this with no luck:
// temp vars used below
var currentTime = new Date()
// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
dateFormat: 'dd.mm.yy',
// minDate: '+10d',
minDate: new Date(currentTime.getYear(), currentTime.getMonth(), 20),
maxDate: '+3w'
});
BR. Anders
UPDATE - Solution
I used the answer from undertakeror and it works just fine. Thnaks for the answer :-)
// temp vars used below
var currentTime = new Date();
var startDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -10); // 10 days before next month
var startDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -1); // one day before next month
var endDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 3); // 3rd of next month
var endDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 10); // 10th of next month
// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
dateFormat: 'dd.mm.yy',
minDate: startDateFrom,
maxDate: startDateTo
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个不错的插件,有很多配置选项 http://plugins.jquery.com/project/datepicker 。您可以在此处找到文档 http://www.kelvinluck.com /assets/jquery/datePicker/v2/demo/documentation.html 和一些演示 http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/
话虽如此,我不知道它是否比您尝试过的更容易使用,但是这个想法是你仍然需要自己计算天数,比如 http://jsfiddle.net/m2HPr/2 /
希望有帮助
This is a nice plugin and has a lot of configuration options http://plugins.jquery.com/project/datepicker . You can find the documentation here http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/documentation.html and some demos here http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/
that being said, i don't know if it is easier to use then the one you tried, but the idea is that you still have to compute the days yourself, something like http://jsfiddle.net/m2HPr/2/
Hope it helps