日期:2014-05-16  浏览次数:20799 次

ExtJs中怎么动态添加一个textfield的文本框 - Web 开发 / Ajax
在form表单中点击某个按钮,实现动态添加一个textfield的文本框到form里面。
求代码。。监听事件应该怎么写?


------解决方案--------------------
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" 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>
var oForm;
var n=0;
Ext.onReady(function(){
    oForm    = new Ext.FormPanel({
        renderTo:"form_panel",
        layout:"form",
        hideLabels:false,
        border:false,
        labelAlign:"right",
        labelWidth:70,
        items:[
            {xtype:'button',text:'click',listeners:{
                click:function(){
                    n++;
                    var fd = new Ext.form.TextField({name:'xx'+n,id:'xx'+n,fieldLabel:'field'+n});
                    oForm.items.add(oForm.items.getCount(), fd);
                    oForm.doLayout();
                }
            }}
        ]
    });
});

</script>
<div id="form_panel"></div>