我正在使用这个jquery时间选择器:http : //jonthornton.github.io/jquery-timepicker/
开箱即用地提供了一个下拉菜单,小时数增加了30分钟,这正是我所需要的。
如何在时间选择器中禁用当前时间之前的所有时间?
例如,如果当前时间是04:10 PM,则应禁用04:30之前的所有值。
API仅提供以下信息:
disableTimeRanges禁用某些时间范围的选择。输入是一组时间对,例如`[['3:00 am','4:30 am'],['5:00 pm','8:00 pm']]。间隔的开始将被禁用,但结束将不会被禁用。默认值:[]
现有代码:
var timeOptions = {
'timeFormat': 'h:i A'
};
$('#pickTime').timepicker(timeOptions);
Run Code Online (Sandbox Code Playgroud)
尝试这个:
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())]]
};
Run Code Online (Sandbox Code Playgroud)
或者您可以使用最短时间:
var timeOptions = {
'timeFormat': 'h:i A',
'minTime': getCurrentTime(new Date())
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9033 次 |
| 最近记录: |