您需要更改插件来实现这一点。这里的解决方案可能不是最有效的方法,但它让您了解从哪里开始使用代码。
在jquery.simple-dtpicker.js
文件上,查找下面的块并应用更改。
更新:根据 OP 请求,添加了一个新选项以使解决方案更加灵活。现在通过了等待的分钟数。逻辑也略有改变。
var isFutureOnly = $picker.data("futureOnly");
// Adding option to control the number of minutes to consider when calculating
// the future date/time
var minuteToFuture = $picker.data("minuteToFuture");
var isOutputToInputObject = option.isOutputToInputObject;
...
// Before the change
//var isPastTime = (hour < todayDate.getHours() && || (hour == todayDate.getHours() && min < todayDate.getMinutes());
// After the change (consider the 'minuteToFuture' minutes gap)
var dateTimeLimit = new Date();
dateTimeLimit.setMinutes(dateTimeLimit.getMinutes() + minuteToFuture);
var dateTimeToCheck = new Date();
dateTimeToCheck.setHours(hour);
dateTimeToCheck.setMinutes(min);
var isPastTime = dateTimeToCheck <= dateTimeLimit;
...
$picker.data("futureOnly", opt.futureOnly);
// Adding option to control the number of minutes to consider when calculating
// the future date/time
$picker.data("minuteToFuture", opt.minuteToFuture);
$picker.data("state", 0);
...
/**
* Initialize dtpicker
*/
$.fn.dtpicker = function(config) {
var date = new Date();
var defaults = {
"inputObjectId": undefined,
"current": null,
"dateFormat": "default",
"locale": "en",
"animation": true,
"minuteInterval": 30,
"firstDayOfWeek": 0,
"closeOnSelected": false,
"timelistScroll": true,
"calendarMouseScroll": true,
"todayButton": true,
"dateOnly": false,
"futureOnly": false,
// Adding option to control the number of minutes to consider when calculating
// the future date/time
"minuteToFuture": 30
}
...
/**
* Initialize dtpicker, append to Text input field
* */
$.fn.appendDtpicker = function(config) {
var date = new Date();
var defaults = {
"inline": false,
"current": null,
"dateFormat": "default",
"locale": "en",
"animation": true,
"minuteInterval": 30,
"firstDayOfWeek": 0,
"closeOnSelected": false,
"timelistScroll": true,
"calendarMouseScroll": true,
"todayButton": true,
"dateOnly" : false,
"futureOnly": false,
// Adding option to control the number of minutes to consider when calculating
// the future date/time
"minuteToFuture": 30
}
要使用新选项:
$(function () {
$('#myInput').appendDtpicker({
"minuteToFuture": 30
});
});