我一直在我的网站上使用这个DateTime选择器,我每周都有一个时间表,它的开始和结束时间取决于一周中的哪一天,我想禁用超出时间表范围的时间,包括分钟,我的惊喜是什么?我找不到任何关于禁用分钟的文档。我决定将DateTime插件换成另一个插件,但我必须更改已有的所有代码。所以我又回到了eonasdan-datetimepicker,有什么方法可以解决这个问题吗?我可以成功地禁用小时,但我说的是分钟。
发布于 2017-05-29 23:02:10
您可以使用选项disabledTimeIntervals,但这只适用于特定的日期(时刻),然后您必须指定每个可用日期的间隔。我做了这样的事情:
var addingColacionInterval = function (disabledTimeIntervals, currDate) {
var intervalsPerDay = {
1: { //1-7 where 1 is Monday and 7 is Sunday
startHour:15,
startMinute: 40,
durationInMinutes: 30
},
2: {
startHour:8,
startMinute: 20,
durationInMinutes: 50
}
// etc
}
var intervalForWeekDay = intervalPerDay[currDate.isoWeekday()]; //.isoWeekday(); // returns 1-7 where 1 is Monday and 7 is Sunday
var initialTime = currDate.clone().set({ hour: intervalForWeekDay.startHour, minute: intervalForWeekDay.startMinute });
disabledTimeIntervals.push([initialTime, initialTime.clone().add(parseInt(intervalForWeekDay.durationInMinutes), 'minutes')]);
}
var minDate = moment("the min selectable date");
var maxDate = moment("the max allowed date");
//for disable colación minutes intervals we can't use disableHours because don't work with minutes disabledTimeIntervals doesn't work for all days (like, but you have to loop trought
var disabledTimeIntervals = [];
var currDate = minDate.clone().startOf('day');
var lastDate = maxDate.clone().endOf('day');
do {
addingColacionInterval(disabledTimeIntervals, currDate);
} while (currDate.add(1, 'days').diff(lastDate) < 0);
var disabledHours = [0, 1, 2, 3, 4, 5, 6, 7, 23];
$scope.disableDays = [];
if ($scope.import.disableSunday) {
$scope.disableDays = [0];
}
//
$scope.dateSecOptions = {
minDate: minDate.format('YYYY-MM-DD'),
maxDate: maxDate.format('YYYY-MM-DD'),
disabledHours: disabledHours,
disabledTimeIntervals: disabledTimeIntervals,
stepping: 10,
};与disabledTimeIntervals相比,还有一个选项disabledHours,它允许您在日历小部件中禁用所有可用(可选)天的小时数。
发布于 2016-08-05 03:43:35
你到底想要什么?例如,只允许用户选择特定的时间,如半小时30或整个小时? 00,因为如果是这样的话,您可以使用步进函数,它所做的是,当用户选择向上或向下箭头时,分钟会随着您的选择而前进,例如30分钟:
$(document).ready(function () {
$('#datetimepicker4').datetimepicker({
stepping:30
});
});https://stackoverflow.com/questions/38770368
复制相似问题