EXTJS4.0 datefield时间控件更改为获取服务器时间

       
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赋值语句释放掉,无大碍,顶多就是用浏览器的时间先赋值一次  代码再用服务器的时间来一次


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值