[英]jQuery Date and timepicker different time on specific day
im using date and timepicker for a reservation form and i need your help.我正在使用日期和时间选择器进行预订,我需要您的帮助。 http://xdsoft.net/jqplugins/datetimepicker/ <- source code where i got it from http://xdsoft.net/jqplugins/datetimepicker/ <- 我从哪里得到它的源代码
i would like to set a specific time period only on sunday.我想只在星期天设置一个特定的时间段。 so every other day the 'allowtimes' is from 18:30 tot 23:15 but on sunday its 12:30 till 22:00所以每隔一天“允许时间”是从 18:30 到 23:15 但周日是 12:30 到 22:00
this is de code i use这是我使用的代码
$('#datum').datetimepicker({
lang:'nl',
i18n:{
de:{
months:[
'Januari','Februair','Maart','April',
'Me','Juni','Juli','Augustus',
'September','Oktober','November','December',
],
dayOfWeek:[
"Zo.", "Ma", "Di", "Wo",
"Do", "Vr", "Za.",
]
}
},
dayOfWeekStart: 1,
minDate: 0,
formatTime:'H:i',
formatDate:'d.m.Y',
minTime:'18:30',
maxTime:'23:15',
defaultTime:'18:30',
onSelectTime: function(){ },
allowTimes:['18:30','18:45','19:00','19:15','19:30','19:45','20:00','20:15','20:30','20:45','21:00','21:15','21:30','21:45','22:00','22:15','22:30','22:45','23:00','23:15'],
beforeShowDay: function(date) {
var day = date.getDay();
return [(day == 0 || day >4 ), ""]; // Sunday or after Wednesday.
}
});
thnx in advance, any help would be much appreciated提前谢谢,任何帮助将不胜感激
Not sure if you found a solution but posting anyway in case someone else needs help:不确定您是否找到了解决方案,但还是发帖以防其他人需要帮助:
For Sundays and Saturdays we want shorter work hours.对于周日和周六,我们希望缩短工作时间。
var datePickerTime = function(currentDateTime) {
// 'this' is jquery object datetimepicker
var day = currentDateTime.getDay();
if (day === 0 || day === 6) {
this.setOptions({
allowTimes: ["09:00", "10:00", "11:00", "12:00"]
});
} else {
this.setOptions({
allowTimes: ["08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00"]
});
}
};
$('#txtCallDate').datetimepicker({
minDate: '0',
minDateTime: dt,
onChangeDateTime: datePickerTime
});
I believe you have to set the time range in the constructor and in the callback for date change.我相信您必须在构造函数和日期更改的回调中设置时间范围。 And I believe the correct callback is onSelectDate
rather than onChangeDateTime
- using the latter will create flickering and a reset of the time selection widget as it is scrolled (but nevertheless, thanks to @WillemNicolaas for pointing me in the right direction).而且我相信正确的回调是onSelectDate
而不是onChangeDateTime
- 使用后者会在滚动时产生闪烁和时间选择小部件的重置(但是,感谢@WillemNicolaas 为我指明了正确的方向)。 The logic below shows weekday hours of 9AM-7PM and weekend hours of 11AM-7PM, which was what was wanted in my case.下面的逻辑显示了工作日的上午 9 点到晚上 7 点,周末的时间是上午 11 点到晚上 7 点,这正是我想要的。
d = new Date();
weekendTimes = [
'11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00'
];
weekdayTimes = [
'9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00'
];
if ((d.getDay() == 6) || (d.getDay() == 0)) {
times = weekendTimes;
} else {
times = weekdayTimes;
}
var datePickerTime = function(currentDateTime) {
// 'this' is jquery object datetimepicker
var day = currentDateTime.getDay();
if (day === 0 || day === 6) {
this.setOptions({
allowTimes: weekendTimes
});
} else {
this.setOptions({
allowTimes: weekdayTimes
});
}
};
jQuery('input[name="order_delivery_date"]').datetimepicker({
inline:true,
minDate:0,
onSelectDate: datePickerTime,
defaultDate: d,
allowTimes: times,
formatTime:'g:i A'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.