我正在使用这个 jquery 时间选择器:http://jonthornton.github.io/jquery-timepicker/
它提供了一个开箱即用的输入下拉列表,其中小时数按 30 分钟递增,这正是我所需要的。
如何在时间选择器中禁用当前时间之前的所有时间?
例如,如果当前时间为下午 04:10,则应禁用 04:30 之前的所有值。
API 仅提供此信息:
disableTimeRanges Disable selection of certain time ranges. Input is an array of time pairs, like `[['3:00am', '4:30am'], ['5:00pm', '8:00pm']]. The start of the interval will be disabled but the end won't. default: []
现有代码:
var timeOptions = {
'timeFormat': 'h:i A'
};
$('#pickTime').timepicker(timeOptions);
最佳答案
试试这个:
function getCurrentTime(date) {
var hours = date.getHours(),
minutes = date.getMinutes(),
ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
return hours + ':' + minutes + ' ' + ampm;
}
var timeOptions = {
'timeFormat': 'h:i A',
'disableTimeRanges': [['12am', getCurrentTime(new Date())]]
};
或者你可以使用最短时间:
var timeOptions = {
'timeFormat': 'h:i A',
'minTime': getCurrentTime(new Date())
};
关于jquery - timepicker 禁用当前时间之前的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30167823/