EXT中回车事件应用

EXT中Viewport中的item实现回车事件操作:
方法一:listeners监听
如下面的代码:

this.viewport = new Ext.Viewport({
                frame:true,
                layout:"border",
                margins:'5',
                items:[{
                    xtype:'toolbar',
                    region: 'north',
                    border:false,
                    style:'border:none;',
                    id:'topToolbar',
                    items:[{
                        xtype:'label',
                        text:'查找脚本内容:'
                    },{
                        xtype:'textfield',
                        id:'txtValue',
                        width:200,
                        emptyText:'输入要查找的脚本内容',
                        listeners :{
                            specialkey : function(field,e){
                                if (e.getKey() == Ext.EventObject.ENTER) {
                                    var searchValue = Ext.getCmp("txtValue").getValue();
                                    var url = 'script!getSearchScript.jhtml?searchValue=' + searchValue;
                                    setActiveTab(url,"搜索结果");
                                }
                            }
                        }
                    }]
                  }]

                })

其中listeners是对回车事件的监听,当 e.getKey()==Ext.EventObject.ENTER时,在function中增加回车事件操作。

listeners :{
                            specialkey : function(field,e){
                                if (e.getKey() == Ext.EventObject.ENTER) {
                                    var searchValue = Ext.getCmp("txtValue").getValue();
                                    var url = 'script!getSearchScript.jhtml?searchValue=' + searchValue;
                                    setActiveTab(url,"搜索结果");
                                }
                            }
          }

方法二:绑定键盘回车事件:

                            {
                                xtype:'textfield',
                                ctCls:'searchBox-fill',
                                name:'q',
                                id:'ceshi',
                                style:'width: 93%;background-image: url(../res/img/find.gif);background-position: right;background-repeat: no-repeat;',
                                emptyText:"表名称或表id"
                            }
                    var addListenersToQ=function(){
                        var text = Ext.get("ceshi").dom;
                        new Ext.KeyMap(Ext.get(text), {
                            key: Ext.EventObject.ENTER,
                            fn: function(){
                                doSearch(tree.getRootNode(),"");//要执行的操作
                            },
                            scope: this
                        });
                    }

通过Ext.KeyMap来绑定item中的元素。
通过Ext.get(“ceshi”).dom来获得EXT.Element对象中的dom元素。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值