EXT表格
纯表单
<html> <head><title>演示</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" type="text/css" media="all" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script src="extjs/build/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var form1 = new Ext.form.FormPanel({ title:'综合查询', applyTo:'search_form', frame:false, items: [{ }] }); }); </script> </head> </head> <body> <div id="hello"></div> <div id='search_form'></div> </body> </html>
注意:frame:false,和frame:true的差异
基本表单
<html> <head><title>演示</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" type="text/css" media="all" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script src="extjs/build/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var form1 = new Ext.form.FormPanel({ title:'综合查询', applyTo:'search_form', frame:true, items: [{ xtype: 'textfield', fieldLabel: '名称', name: 'title' },{ xtype: 'textfield', fieldLabel: '内容', name: 'director' }], buttons:[{ text:'开始查询', handler:function(){ doSearch(); } }] }); var doSearch=function() { Ext.Msg.alert('提示','操作已经成功'); } }); </script> </head> </head> <body> <div id="hello"></div> <div id='search_form'></div> </body> </html>
表单跳转:
var doSearch=function() { //Ext.Msg.alert('提示','操作已经成功'); location.href ='d.php'; }
表单元素设置ID以及获取
设置id
items: [{ xtype: 'textfield', fieldLabel: '名称', name: 'title', id:'tt' },
获取id:
Ext.Msg.alert('提示','操作已经成功'+Ext.getDom("title").id);
完整代码
<html> <head><title>演示</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" type="text/css" media="all" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script src="extjs/build/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var form1 = new Ext.form.FormPanel({ title:'综合查询', applyTo:'search_form', frame:true, items: [{ xtype: 'textfield', fieldLabel: '名称', name: 'title', id:'tt' }, { xtype: 'textfield', fieldLabel: '内容', name: 'director' }], buttons:[{ text:'开始查询', handler:function(){ doSearch(); } }] }); var doSearch=function() { Ext.Msg.alert('提示','操作已经成功'+Ext.getDom("title").id); } }); </script> </head> </head> <body> <div id="hello"></div> <div id='search_form'></div> </body> </html>
如果不设置id系统会默认给其id
注释// id:'tt'
比较就明白了
获取文本框内容
Ext.Msg.alert('提示','操作已经成功'+Ext.getDom("title").value);
或者
Ext.get('title').getValue()
声明示定义文本框以及获取值
<html> <head><title>演示</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" type="text/css" media="all" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script src="extjs/build/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var txtAccount = new Ext.form.TextField({ width:120,fieldLabel:'用户名' }); var form1 = new Ext.form.FormPanel({ title:'综合查询', applyTo:'search_form', frame:true, items: [{ xtype: 'textfield', fieldLabel: '名称', name: 'title' }, {columnWidth:.5,layout: 'form', items: [txtAccount] }, { xtype: 'textfield', fieldLabel: '内容', name: 'director' }], buttons:[{ text:'开始查询', handler:function(){ doSearch(); } }] }); var doSearch=function() { //Ext.Msg.alert('提示','操作已经成功'+Ext.getDom("title").id); Ext.Msg.alert('提示','操作已经成功'+txtAccount.getValue()); } }); </script> </head> </head> <body> <div id="hello"></div> <div id='search_form'></div> </body> </html>
定义单选框以及获取选中
<html> <head><title>演示</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" type="text/css" media="all" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script src="extjs/build/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var txtAccount = new Ext.form.TextField({ width:120,fieldLabel:'用户名' }); var checkFlag = new Ext.form.Checkbox({boxLabel:'是',fieldLabel:'是否选择',value:1}); var form1 = new Ext.form.FormPanel({ title:'综合查询', applyTo:'search_form', frame:true, items: [{ xtype: 'textfield', fieldLabel: '名称', name: 'title' }, {columnWidth:.5,layout: 'form', items: [txtAccount] }, {columnWidth:.5,layout: 'form', items: [checkFlag] }, { xtype: 'textfield', fieldLabel: '内容', name: 'director' }], buttons:[{ text:'开始查询', handler:function(){ doSearch(); } }] }); var doSearch=function() { //Ext.Msg.alert('提示','操作已经成功'+Ext.getDom("title").id); //Ext.Msg.alert('提示','操作已经成功'+txtAccount.getValue()); var rejectFlag =0; if(checkFlag.checked==true) { rejectFlag=1; } Ext.Msg.alert('提示','操作已经成功'+rejectFlag); } }); </script> </head> </head> <body> <div id="hello"></div> <div id='search_form'></div> </body> </html>
下拉框绑定以及获取选中值
<html> <head><title>演示</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" type="text/css" media="all" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script src="extjs/build/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var txtAccount = new Ext.form.TextField({ width:120,fieldLabel:'用户名' }); var checkFlag = new Ext.form.Checkbox({boxLabel:'是',fieldLabel:'是否选择',value:1}); var DeptDs = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ method:'post', url: 'd.php', params:{test:'load'} }), autoLoad:true, reader:new Ext.data.JsonReader({ root : 'data',id:'dddd', totalProperty : 'totalCount' }, [{name : 'value'},{name : 'text'}]) }); var comboDepts = new Ext.form.ComboBox({ store:DeptDs, valueField :"value", displayField: "text",id:'value', mode: 'local',allowBlank:true, emptyText:'选择省份.....',width:220,fieldLabel: '省份', blankText:'选择省份', editable: true,anyMatch:true,tabIndex:4, triggerAction: 'all' }); var form1 = new Ext.form.FormPanel({ title:'综合查询', applyTo:'search_form', frame:true, items: [{ xtype: 'textfield', fieldLabel: '名称', name: 'title' }, {columnWidth:.5,layout: 'form', items: [txtAccount] }, {columnWidth:.5,layout: 'form', items: [checkFlag] }, {columnWidth:.5,layout: 'form', items: [comboDepts] }, { xtype: 'textfield', fieldLabel: '内容', name: 'director' }], buttons:[{ text:'开始查询', handler:function(){ doSearch(); } }] }); var doSearch=function() { //Ext.Msg.alert('提示','操作已经成功'+Ext.getDom("title").id); // //Ext.Msg.alert('提示','操作已经成功'+txtAccount.getValue()); //Ext.Msg.alert('提示','操作已经成功'+Ext.get('title').getValue()); Ext.Msg.alert('提示','操作已经成功'+comboDepts.getValue()); } }); </script> </head> </head> <body> <div id="hello"></div> <div id='search_form'></div> </body> </html>
d.php返回的数据
{"success":true,"data":[
{"value":"010","text":"北京"},
{"value":"021","text":"上海"}
]}
ajax提交表单数据
<html> <head><title>演示</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" type="text/css" media="all" href="extjs/resources/css/ext-all.css" /> <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="extjs/ext-all.js"></script> <script src="extjs/build/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript"> Ext.onReady(function(){ Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var simple = new Ext.FormPanel({ labelWidth: 75, baseCls: 'x-plain', defaults: {width: 150}, defaultType: 'textfield', items: [{ fieldLabel: '帐户', name: 'name', allowBlank:false, blankText:'帐户不能为空' },{ inputType:'password', fieldLabel: '密码', name: 'pwd', allowBlank:false, blankText:'密码不能为空' } ], buttons: [{ text: '登录系统', type: 'submit', handler:function(){ if(simple.form.isValid()){ //ExtJs Ajax表单提交 simple.form.doAction('submit',{ url:'d1.php', method:'post', params:'', success:function(result,request){ //alert(action.result.msg); Ext.Msg.alert('操作成功',request.result.data);//json是什么这里就是什么 }, failure:function(){ Ext.Msg.alert('警告', '未知的失败原因!'); } }); } } }] }); win = new Ext.Window({ id:'win', title:'用户登陆', layout:'fit', width:300, height:150, plain:true, bodyStyle:'padding:5px;', maximizable:false, closeAction:'close', closable:false, collapsible:true, plain: true, buttonAlign:'center', items:simple }); win.show(); }); </script> </head> </head> <body> <div id="hello"></div> </body> </html>
验证的d.php页面
<?php $arr = array( 'success' => 'true', 'data' => '1001111111111111111111111' ); $json_string = json_encode($arr); echo $json_string; ?>
必须返回json的格式切要有success,类似这样的:
("{success:true,info:'1001111111111111111111111!'}");
=========================================