我的输入字段如下-
<input type="text" maxlength="8" placeholder="" class="time-icn form-control ui-timepicker-input valid" name="ReminderTime" id="ReminderTime" class="ReminderTime" value="" autocomplete="off">
按如下方式添加时间选择器
$("#ReminderTime").timepicker({
"showDuration": true,
"timeFormat": "g:i A",
"step": 15,
"forceRoundTime": true,
"maxTime": "11:45pm",
"className": "timepicker-width",
"scrollDefault": "now",
});
我到底是做什么的?
获取当前小时与 date.getHours()
和分钟date.getMinutes()
然后将其设置为 minTime
,我删除了用于选择今天剩余时间的maxTime
,也代替step
,使用 interval
和你的timeFormat
是错误的。
var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
$("#ReminderTime").timepicker({
"showDuration": true,
"interval": 15,
"timeFormat": "h:mm p",
"forceRoundTime": true,
"minTime": "" + hour + ":" + minute + "",
"className": "timepicker-width",
"scrollDefault": "now",
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
<input type="text" maxlength="8" placeholder="" class="time-icn form-control ui-timepicker-input valid" name="ReminderTime" id="ReminderTime" class="ReminderTime" value="" autocomplete="off">