我在页面上有多个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
};
答案 0 :(得分:1)
使用:focus
伪选择器,如下所示:
$('.datetime:focus').datepicker('setDate', now_utc);
或者,您也可以为每个日期选择器指定一个特定的 ID ,以便您可以选择:
$('#idpicker').datepicker('setDate', now_utc);