1

我在一个页面上有多个 jquery datetimepickers。尝试在“今天”按钮单击上设置日期,但为页面上的所有日期时间选择器设置以下日期?

如何仅设置具有焦点的那个(使用 Trent Richarsons jquery datetimepicker)?

    $.datepicker._gotoToday = function (id) {
    var inst = this._getInst($(id)[0]),
    $dp = inst.dpDiv;
    this._base_gotoToday(id);
    var tp_inst = this._get(inst, 'timepicker');
    now = new Date();
    var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
    this._setTime(inst, now_utc);
    $('.datetime').datepicker('setDate', now_utc);  // <- this woks but sets date for all datetimepickers!  how to I set for current focus datetimepicker
};
4

1 回答 1

1

使用:focus伪选择器,如下所示:

$('.datetime:focus').datepicker('setDate', now_utc);

或者,您也可以为每个日期选择器指定一个特定的id,以便您可以通过它进行选择:

$('#idpicker').datepicker('setDate', now_utc);
于 2012-11-28T01:10:21.523 回答