ext使用学习4

来源:互联网 发布:大数据时代 ppt 编辑:程序博客网 时间:2024/06/07 20:20

DomQuery基础

     使用函数“Ext.query”但读者须谨记它是“Ext.DomQuery.select()”的简写方式

 第一部分:元素选择符Selector

      // 这个查询会返回有两个元素的数组因为查询选中对整个文档的所有span标签。

         Ext.query("span");

    按id获取标签,你需要加上“#”的前缀:

   // 这个查询会返回包含我们foo div一个元素的数组!

        Ext.query("#foo");

    按class name获取标签,你需要加上“.”的前缀:

      /*这个查询会返回有一个元素的数组, 包含与之前例子一样的div但是我们使用了class name来获取*/ 

      Ext.query(".foo"); 


     你也可以使用关键字“*”来获取所有的元素: 

    // 这会返回一个数组,包含文档的所有元素。 

       Ext.query("*"); 

   要获取子标签,我们只须在两个选择符之间插入一个空格: 

    // 这会返回有一个元素的数组,包含p标签的div标签 

           Ext.query("div p"); 

       // 这会返回有两个元素的数组,包含span标签的div标签 

        Ext.query("div span");


第二部分:属性选择符Attributes selectors

        这些选择符可让你得到基于一些属性值的元素。属性指的是html元素中的href, id 或 class。

        // 我们检查出任何存在有class属性的元素。

             Ext.query("*[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]");



第三部分: CSS值元素选择符

       它的格式规定是这样的:

       元素{属性 操作符 值} 

      注意我在这里是怎么插入一个不同的括号。 所以,操作符(operators)和属性选择符(attribute selectors)是一样的。

      // 获取所以红色的元素

             Ext.query("*{color=red}");

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

             Ext.query("*{color=red} *{color=pink}"); 

     // 获取所有不是红色文字的元素

             Ext.query("*{color!=red}");

          // 获取所有颜色属性是从“yel”开始的元素 

                Ext.query("*{color^=yel}"); 

        // 获取所有颜色属性是以“ow”结束的元素 

                 Ext.query("*{color$=ow}"); 


第四部分:伪类选择符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(td)")

             /* this one gives us every LABEL that is preceded by an INPUT */ 

                Ext.query("label:prev(input)")






原创粉丝点击