我正在尝试修改现有的 datepicker 插件(Pikaday)以在某些呈现的 HTML(在插件中呈现)中显示选定的日期。
我已经确定以下 setDate 方法/函数返回我想要使用的日期字符串,但我不确定如何提取它并在我的函数中使用它。
setDate 方法显示为:
setDate: function(date, preventOnSelect)
{
if (!date) {
this._d = null;
if (this._o.field) {
this._o.field.value = '';
fireEvent(this._o.field, 'change', { firedBy: this });
}
return this.draw();
}
if (typeof date === 'string') {
date = new Date(Date.parse(date));
}
if (!isDate(date)) {
return;
}
var min = this._o.minDate,
max = this._o.maxDate;
if (isDate(min) && date < min) {
date = min;
} else if (isDate(max) && date > max) {
date = max;
}
this._d = new Date(date.getTime());
setToStartOfDay(this._d);
this.gotoDate(this._d);
if (this._o.field) {
this._o.field.value = this.toString();
fireEvent(this._o.field, 'change', { firedBy: this });
//I want to return `this._o.field.value`
}
if (!preventOnSelect && typeof this._o.onSelect === 'function') {
this._o.onSelect.call(this, this.getDate());
}
}
我想回来this._o.field.value
。
有谁知道我怎么能抓住它并在我的功能中使用它?
PS,我是 PHP OOP 背景,所以我对 JS OOP 的理解可能有所欠缺,抱歉。我的 HTML 渲染功能:
renderHeading = function(instance, c, year, month, days)
{
var opts = instance._o;
var html = '<div class="pika-heading">';
html += '<h3 class="pika-heading-year">' + year + '</h3>';
html += '<h1 class="pika-heading-date">' + opts.i18n.weekdaysShort[day] + ', ' + opts.i18n.monthsShort[month] + '</h1>';
return html += '</div>';
}