var fs = Ext.create('Ext.form.Panel', {
region : 'north',
frame : true,
bodyStyle : 'padding:4px 2px 3px 4px',
width : document.body.clientWidth,
fieldDefaults : {
labelAlign : 'left',
msgTarget : 'side'
},
items : [ {
xtype : 'container',
anchor : '100%',
layout : 'column',
items : [ {
xtype : 'container',
columnWidth : .2,
layout : 'anchor',
defaultType : 'datefield',
items : {
fieldLabel : '日期',
anchor : '90%',
id:'time',
format : 'Y-m-d',
timePicker : true,
editable : false,
allowBlank : false,
//value : Ext.Date.add(new Date(), Ext.Date.DAY, 1),
listeners : {
'change' : specchangedatefun
}
}
} ]
} ]
});
因为 value : Ext.Date.add(new Date(), Ext.Date.DAY, 1),
会默认获取当前浏览器所在机器的时间,所以如果用户主动更改时间的话,会有些许问题
在页面开始加载的时候 我就先获取服务器的时间 然后传到前台 给前台的日期控件赋值
Ext.Ajax.request( {
timeout : 3000,
url : 'getdate.action',
success : function(response, config) {
json = Ext.JSON.decode(response.responseText);
var date=new Date(json.date);
var d=Ext.Date.add(date,Ext.Date.DAY, 1)
Ext.getCmp('time').setValue(d);
},
failure : function(response,options) {
}
})//Ajax end
如果遇到出现什么getFullYear的错误的话 可以先把 上面注释掉的value赋值语句释放掉,无大碍,顶多就是用浏览器的时间先赋值一次 代码再用服务器的时间来一次