您需要更改插件才能實現該目標。這裏的解決方案可能並不是最有效的方法,但它給了你一個關於從哪裏開始玩代碼的想法。
在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
});
});
感謝這個工作!我有另一個問題,也許你可以幫助我:)我需要從我的HTML傳遞一個整數到這個JS文件...也許像「minutesToAdd」:30,...有什麼辦法可以做這發生了嗎?或者有其他方法嗎?再次感謝:) –
我已經更新了我的答案。如果你需要整個文件,只需給我你的電子郵件地址,我可以發送給你。 – melancia
不能相信只有1票贊成。 – radpin