2

我希望 datetimepicker 上的“现在”按钮在单击时关闭小部件。就目前而言,用户必须单击“现在”和“完成”。

我的应用程序有很多时间戳,所以这最终很乏味。谢谢。

有谁知道这是可配置的,还是我需要破解 jQuery 插件代码(请说前者)。谢谢。

4

2 回答 2

1

只需使用onSelect事件触发完成按钮(或关闭对话框)

于 2012-11-26T15:39:29.673 回答
0

我完成了在 Trent (版本 1.6.1)中添加closeOnNowClick设置和更改:_gotoTodayjquery-ui-timepicker-addon.js

$.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
});

I also noticed that sometimes tzoffset is returned as string, and now.getMinutes() + now.getTimezoneOffset() + tzoffset results in absolutely weird values. So I have added the parseInt call to convert tzoffset to int.

于 2015-12-24T11:49:27.507 回答