我目前将 XDSoft DateTimePicker ( http://xdsoft.net/jqplugins/datetimepicker/ ) JQuery 集成到我的网站中,并希望禁用已经过去的时间。目前,如果我选择今天,那么我仍然可以选择已经过去的时间。
我尝试使用 minTime:0 但这也会禁用后续日子的时间。我希望能够选择开始和结束时间(例如上午 9 点至下午 5:30),我可以使用最短时间和最长时间来执行此操作,但我无法禁用今天已经过去的时间。
下面是我的脚本:
<script>
jQuery('#datetimepicker3').datetimepicker({
minDate: 0,
step: 60,
minTime: '09:00',
maxTime: '17:30',
todayButton: true,
format: 'd.m.Y H:i',
inline: true,
lang: 'en'
});</script>
最佳答案
是的,将 minTime 设置为 0 也会禁用随后几天的时间。您需要根据日期更改 minTime 选项。如果是今天,minTime 将保持不变,否则 minTime 将设置为 false。
$("#element").datetimepicker({ format: 'Y-m-d H:i', minDate: 0, minTime: 0, onSelectDate: function(ct) {
var dtob = new Date(),
current_date = dtob.getDate(),
current_month = dtob.getMonth() + 1,
current_year = dtob.getFullYear();
// today's date
var full_date = current_year + '-' +
( current_month < 10 ? '0' + current_month : current_month ) + '-' +
( current_date < 10 ? '0' + current_date : current_date );
// compare today's date to the date chosen
if(ct.dateFormat('Y-m-d') == full_date)
this.setOptions({ minTime: 0 });
else
this.setOptions({ minTime: false });
}
});
关于javascript - DateTimePicker - 禁用当天已经过去的时间(JQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32595045/