40020072 发表于 2013-2-7 19:33:41

Ext2的基础知识学习

一、事件监听:
匿名方式:
            Ext.onReady(function(){
                Ext.get('myButton').on('click',function(){
                     alert('you click this button');
                 })
           });
或者写成:
            Ext.onReady(function(){
                Ext.select('myButton').on('click',function(){
                     alert('you click this button');
                 })
           });
 
加上方法名的方式,对重用有利:
          Ext.onReady(function(){
               var clickButton=function(){
                   alert('you click thsi button');
               }
          Ext.get('myButton').on('click',clickButton);
          //或者Ext.select('myButton').on('click',clickButton);
});
 
二、DomQuery基础
      1、元素选择符Selector
       ★// 这个查询会返回所有span标签组成的数组。
       Ext.query("span");
       ★// 这个查询会返回有一个元素的数组因为查询顾及到了foo这个id。
       Ext.query("span", "foo");
       ★//按id获取标签,你需要加上“#”的前缀
       Ext.query("#foo");
       ★//按class name获取标签,你需要加上“.”的前缀
       Ext.query(".foo");
       ★//你也可以使用关键字“*”来获取所有的元素,这会返回一个数组,包含文档的所有元素。
       Ext.query("*");
       ★//要获取子标签,我们只须在两个选择符之间插入一个空格
         // 这会返回有一个元素的数组,包含p标签的div标签
       Ext.query("div p");
         // 这会返回有两个元素的数组,包含span标签的div标签
       Ext.query("div span");
 
       2、属性选择符Attributes selectors
       这些选择符可让你得到基于一些属性值的元素。属性指的是html元素中的href, id 或 class。
       ★// 这会得到class等于“bar”的所有元素
       Ext.query("*");
       ★// 这会得到class不等于“bar”的所有元素
       Ext.query("*");
       ★// 这会得到class从“b”字头开始的所有元素
       Ext.query("*");
       ★//这会得到class由“r”结尾的所有元素
        Ext.query("*");
       ★//这会得到在class中抽出“a”字符的所有元素
       Ext.query("*");
 
       3、CSS值元素选择符
       基于这个CSS的颜色值我们不会作任何查询,但可以是其它的内容。它的格式规定是这样的: 元素{属性 操作符 值}  注意我在这里是怎么插入一个不同的括号。 所以,操作符(operators)和属性选择符(attribute selectors)是一样的。
       // 获取所以红色的元素
       Ext.query("*{color=red}"); //
       // 获取所有粉红颜色的并且是有红色子元素的元素
       Ext.query("*{color=red} *{color=pink}"); //
       // 获取所有不是红色文字的元素 Ext.query("*{color!=red}");
       //[html, head, script firebug.js, link, body#ext-gen2.ext-gecko,
       // script ext-base.js, script ext-core.js, span.bar, //a www.extjs.com, div#foo.bar, p, span.bar, a test.html#]
       // 获取所有颜色属性是从“yel”开始的元素 Ext.query("*{color^=yel}"); //
       // 获取所有颜色属性是以“ow”结束的元素 Ext.query("*{color$=ow}"); //
       // 获取所有颜色属性包含“ow”字符的元素
       Ext.query("*{color*=ow}"); //
 
       4、伪类选择符Pseudo Classes selectors
      /* this one gives us the first SPAN child of its parent */ Ext.query("span:first-child"); //     /* this one gives us the last A child of its parent */ Ext.query("a:last-child") // /*

this one gives us the second SPAN child of its parent */
Ext.query("span:nth-child(2)") //
/* this one gives us ODD TR of its parents */
Ext.query("tr:nth-child(odd)") //
/* this one gives us even LI of its parents */
Ext.query("li:nth-child(even)") // /*
this one gives us A that are the only child of its parents */
Ext.query("a:only-child") // /*
this one gives us the checked INPUT */
Ext.query("input:checked") //
/* this one gives us the first TR */
Ext.query("tr:first") // /*
this one gives us the last INPUT */
Ext.query("input:last") // /*
this one gives us the 2nd TD */
Ext.query("td:nth(2)") //
/* this one gives us every DIV that has the "within" string */
Ext.query("div:contains(within)") // /*
this one gives us every DIV that doesn't have a FORM child */
Ext.query("div:not(form)") /*
This one gives use every DIV that has an A child */
Ext.query("div:has(a)") // /*
this one gives us every TD that is followed by another TD. obviously, the one that has a colspan property is ignored. */
Ext.query("td:next
 
三、扩展EXT组件
 
页: [1]
查看完整版本: Ext2的基础知识学习