我希望日期时间选择器上的"现在"按钮在单击小部件时将其关闭。就目前而言,用户必须单击"现在"和"完成"。
我的应用程序有很多时间戳,所以这最终很乏味。谢谢。
有谁知道这是否可配置,或者我需要破解 jQuery 插件代码(请说前者)。谢谢。
只需使用 onSelect
事件触发完成按钮(或关闭对话框)
我完成了在Trent的jquery-ui-timepicker-addon.js
(版本1.6.1)中添加closeOnNowClick
设置和更改_gotoToday
:
$.datepicker._gotoToday = function (id) {
var inst = this._getInst($(id)[0]);
// ***: added to hide dialog on Now click
var closeOnNowClick = this._get(inst, 'closeOnNowClick');
if (typeof(closeOnNowClick) == 'boolean' && closeOnNowClick === true) {
this._hideDatepicker();
}
this._base_gotoToday(id);
var tp_inst = this._get(inst, 'timepicker');
var tzoffset = parseInt($.timepicker.timezoneOffsetNumber(tp_inst.timezone)); // ***: added parseInt here
var now = new Date();
now.setMinutes(now.getMinutes() + now.getTimezoneOffset() + tzoffset);
this._setTime(inst, now);
this._setDate(inst, now);
tp_inst._onSelectHandler();
};
示例用法:
$('#somedate')
.datetimepicker({'dateFormat':'yy-mm-dd',
'timeFormat':'HH:mm',
'timeInput': true,
'closeOnNowClick': true
});
我还注意到有时tzoffset
以字符串形式返回,now.getMinutes() + now.getTimezoneOffset() + tzoffset
会导致绝对奇怪的值。所以我添加了parseInt
调用以将tzoffset
转换为 int。