用Ext写的页面,只能选择年月的日历,当天是31好时会出现的时间与选择不符。
自定义继承DateField来自网友分享,如下代码:
//双击时只显示年月
DateFieldEx = Ext.extend(Ext.form.DateField, {
onTriggerClick : function() {
DateFieldEx.superclass.onTriggerClick.call(this, arguments);
if (this.format.indexOf('d') == -1) {
this.menu.picker.monthPicker.slideIn = function() {
this.show();
}
this.menu.picker.hideMonthPicker = function() {
this.monthPicker.hide();
var d = this.activeDate;
if (d) {
this.setValue(this.activeDate);
this.fireEvent('select', this, this.value);
}
}
this.menu.picker.showMonthPicker();
}
}
}) ;
var cxyd = new DateFieldEx({
"anchor" : "90%",
"selectOnFocus" : true,
"name" : "cxyd",
"fieldLabel" : "查询月度",
"format" : "Y-m",
"altFormats" : "Y-m-d H:i:s|m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d",
"editable" : false,
"labelStyle" : "color:red"
});
cxyd.document = panel;
在js代码中前增加一行代码就可以解决:
Date.defaults.d = 1;