Ext.query详解

Ext.query( String path, [Node root] ) : Array
通过path,在root中选择节点数组,path可以是以下四种选择器之一


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


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lmstone/archive/2008/09/25/2980096.aspx

加支付宝好友偷能量挖...


评论(0)网络
阅读(296)喜欢(1)extjs开发技巧