读书人

Extjs温习笔记(三)

发布时间: 2012-10-27 10:42:26 作者: rapoo

Extjs复习笔记(三)

1、用ext代码往页面中加元素:

?

?

?

3、用handler实现事件添加

?

Ext.onReady(function(){var _panel = new Ext.Panel({renderTo:Ext.getBody(),layout:"form",labelWidth:30,title:"TestPanel",listeners:{"render":function(_panel){ //在render的时候生成文本框,相当于直接添加_panel.add(new Ext.form.TextField({ id:"txt_name",fieldLabel:"姓名"})) ; }}}) ;new Ext.Button({text:"确 定",renderTo:Ext.getBody(),handler:function(){//得到当前页面中的文本框。alert(Ext.getCmp("txt_name").getValue()) ;}}) ;}) ;
?

?和上面的Ext.getCmp方法类似的还有一个Ext.getDom.

官方解释:前者是Looks up an existing?Componentby?id,返回的是The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a Class was found.

后者是?Return the dom node for the passed String (id), dom node, or Ext.Element.

Optional 'strict' flag is needed for IE since it can return 'name' and 'id' elements by using getElementById. Here are some examples:

// gets dom node based on idvar elDom = Ext.getDom('elId');// gets dom node based on the dom nodevar elDom1 = Ext.getDom(elDom);// If we don't know if we are working with an// Ext.Element or a dom node use Ext.getDomfunction(el){    var dom = Ext.getDom(el);    // do something with the dom node}

Note: the dom node to be found actually needs to exist (be rendered, etc) when this method is called to be successful.

?

返回的是一个HTMLElement。

读书人网 >JavaScript

热点推荐