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]");

       ★// 这会得到class不等于“bar”的所有元素

       Ext.query("*[class!=bar]");

       ★// 这会得到class从“b”字头开始的所有元素

       Ext.query("*[class^=b]");

       ★//这会得到class由“r”结尾的所有元素

        Ext.query("*[class$=r]");

       ★//这会得到在class中抽出“a”字符的所有元素

       Ext.query("*[class*=a]");

 

       3、CSS值元素选择符

       基于这个CSS的颜色值我们不会作任何查询,但可以是其它的内容。它的格式规定是这样的: 元素{属性 操作符 值}  注意我在这里是怎么插入一个不同的括号。 所以,操作符(operators)和属性选择符(attribute selectors)是一样的。

       // 获取所以红色的元素

       Ext.query("*{color=red}"); // [div#bar.foo]

       // 获取所有粉红颜色的并且是有红色子元素的元素

       Ext.query("*{color=red} *{color=pink}"); // [span.bar]

       // 获取所有不是红色文字的元素 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}"); // [a www.extjs.com]

       // 获取所有颜色属性是以“ow”结束的元素 Ext.query("*{color$=ow}"); // [a www.extjs.com]

       // 获取所有颜色属性包含“ow”字符的元素

       Ext.query("*{color*=ow}"); // [a www.extjs.com, span.bar]

 

       4、伪类选择符Pseudo Classes selectors

      /* this one gives us the first SPAN child of its parent */ Ext.query("span:first-child"); // [span.bar]    /* this one gives us the last A child of its parent */ Ext.query("a:last-child") // [a www.extjs.com, a test.html#] /*

this one gives us the second SPAN child of its parent */

Ext.query("span:nth-child(2)") // [span.bar]

/* this one gives us ODD TR of its parents */

Ext.query("tr:nth-child(odd)") // [tr, tr]

/* this one gives us even LI of its parents */

Ext.query("li:nth-child(even)") // [li, li] /*

this one gives us A that are the only child of its parents */

Ext.query("a:only-child") // [a test.html#] /*

this one gives us the checked INPUT */

Ext.query("input:checked") // [input#chked on]

/* this one gives us the first TR */

Ext.query("tr:first") // [tr] /*

this one gives us the last INPUT */

Ext.query("input:last") // [input#notChked on] /*

this one gives us the 2nd TD */
Ext.query("td:nth(2)") // [td]

/* this one gives us every DIV that has the "within" string */

Ext.query("div:contains(within)") // [div#bar.foo, div#foo.bar] /*

this one gives us every DIV that doesn't have a FORM child */

Ext.query("div:not(form)") [div#bar.foo, div#foo.bar, div] /*

This one gives use every DIV that has an A child */

Ext.query("div:has(a)") // [div#bar.foo, div#foo.bar, div] /*

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组件

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值