分类: HTML5
2016-12-26 16:07:36
ExtJS中有事需要获得Form表单的值,根据API可知 getValues() 可以获得单签Form表单中所有 Name 值的一个对象。 片段代码如下: var formValues=formpanel.getForm().getValues(); //获取表单中的所有Name键/值对对象 alert(formValues["firstname"]); //输出表单中 firstname 字段的值 console.log(formValues); //输出结果是表单中的所有Name键/值对的一个对象 整体代码如下: /** * Created with JetBrains PhpStorm. * User: std * Date: 13-6-9 * Time: 上午10:55 * To change this template use File | Settings | File Templates. */ Ext.onReady(function(){ // var formpanel=Ext.create("Ext.form.Panel",{ title:"Dynamic Form", draggable:true, frame:true, width:330, height:255, //autoHeight:true, bodyPadding:"7 5 7 5", items:[{ xtype:"fieldset", frame:true, title:"Contact Information", //defaultType: 'textfield', defaults:{xtype:"textfield",labelWidth:80,labelAlign:"right",width:280}, items:[{ fieldLabel:"First Name",emptyText:"First Name",name:"firstname" },{ fieldLabel:"Last Name",emptyText:"Last Name",name:"lastname" },{ fieldLabel:"Company",emptyText:"Company",name:"company" },{ fieldLabel:"Email",emptyText:"Email",name:"email" },{ fieldLabel:"State",xtype:"combobox",emptyText:"请选择",name:"state" },{ fieldLabel:"Date of Birth",xtype:"datefield",emptyText:"请选择日期",name:"dateofbirth" }] }], buttons:[ {text:"确定",handler:function(){ var formValues=formpanel.getForm().getValues(); alert(formValues["firstname"]); console.log(formValues); }}, {text:"取消"} ] }); formpanel.render(Ext.getBody()); });