我是靠谱客的博主 老实曲奇,最近开发中收集的这篇文章主要介绍DomQuery v1.1 高级Tutorial:DomQuery v1.1 Advanced,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Tutorial:DomQuery v1.1 Advanced

From Learn About the Ext JavaScript Library

Jump to: navigation, search
Summary: DomQuery Advanced
Author: Bernard Chhun
Published: september 13th 2007
Ext Version: 1.1
Languages: en.pngEnglish

This tutorial will drive you through some advanced DOM manipulation using the results we may get when we use DomQuery.

page_edit.png DomQuery Advanced

page_edit.png Highlight my DOM damn it!

here's an homage clone to what Karl Swedberg did for the JQuery Manual.

It basically highlights some DOM elements based on what button we clicked on. The Ext code is already in the page and you guys will need to give it the appropriate Ext JS files.


Known bugs

  • the 2nd selector doesn't select all even LI's
  • the 8th selector dies on an error


image:domquery_v1_dot_1_advanced_highlight_my_dom_damnit.png 

none.gif <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
none.gif
< html >
none.gif    
< head >
none.gif        
< meta  http-equiv ="Content-Type"  content ="text/html; charset=iso-8859-1" >
none.gif        
< title > Tutorials - DomQuery </ title >
none.gif        
< script  type ="text/javascript"  src ="../js/firebug/firebug.js" ></ script >
expandedblockstart.gifcontractedblock.gif        
< style > dot.gif
expandedsubblockstart.gifcontractedsubblock.gif            .yellow
{dot.gif}{background-color:yellow;}
expandedblockend.gif        
</ style >
none.gif    
</ head >
none.gif    
< body  id ="body" >
none.gif        
< script  type ="text/javascript"  src ="../ext/ext-base.js" ></ script >
none.gif        
< script  type ="text/javascript"  src ="../ext/ext-core.js" ></ script >
expandedblockstart.gifcontractedblock.gif        
< script > dot.gif
expandedsubblockstart.gifcontractedsubblock.gif        
var domquery = function()dot.gif{
expandedsubblockstart.gifcontractedsubblock.gif            
returndot.gif
expandedsubblockstart.gifcontractedsubblock.gif                init: 
function()dot.gif{
inblock.gif                    Ext.select(
"div.dom-traversal-toggles").on("click",
expandedsubblockstart.gifcontractedsubblock.gif                        
function(e, el)dot.gif{
inblock.gif                            
var id = el.id;
inblock.gif                            id 
= id.replace("dt-link""");
expandedsubblockstart.gifcontractedsubblock.gif                            
if (id != "")dot.gif{
expandedsubblockstart.gifcontractedsubblock.gif                                
var toggler = function(e)dot.gif{
expandedsubblockstart.gifcontractedsubblock.gif                                    
var highlight = function(els)dot.gif{
expandedsubblockstart.gifcontractedsubblock.gif                                        
for (var x = 0 ; x < els.length; x ++)dot.gif{
inblock.gif                                            
var el = Ext.get(els[x]);
expandedsubblockstart.gifcontractedsubblock.gif                                            
if (el) dot.gif{
expandedsubblockstart.gifcontractedsubblock.gif                                                
if (el.hasClass("yellow")) dot.gif{
inblock.gif                                                    el.removeClass(
"yellow");
expandedsubblockstart.gifcontractedsubblock.gif                                                }
elsedot.gif{
inblock.gif                                                    el.addClass(
"yellow");
expandedsubblockend.gif                                                }
    
expandedsubblockend.gif                                            }

expandedsubblockend.gif                                        }

inblock.gif                                        
return els;
expandedsubblockend.gif                                    }
;
inblock.gif 
expandedsubblockstart.gifcontractedsubblock.gif                                    
var highlightHidden = function(els)dot.gif{
inblock.gif                                        
var elmts = highlight(els);
expandedsubblockstart.gifcontractedsubblock.gif                                        
for (var x = 0 ; x < elmts.length; x ++)dot.gif{
inblock.gif                                            
var el = Ext.get(elmts[x]);
expandedsubblockstart.gifcontractedsubblock.gif                                            
if (el) dot.gif{
expandedsubblockstart.gifcontractedsubblock.gif                                                
if (el.hasClass("yellow"))dot.gif{
inblock.gif                                                    el.fadeIn();    
expandedsubblockstart.gifcontractedsubblock.gif                                                }
elsedot.gif{
inblock.gif                                                    el.fadeOut();
inblock.gif                                                    el.removeClass(
"yellow");
expandedsubblockend.gif                                                }
    
expandedsubblockend.gif                                            }
    
expandedsubblockend.gif                                        }

inblock.gif 
expandedsubblockend.gif                                    }

expandedsubblockstart.gifcontractedsubblock.gif                                    
switch(e)dot.gif{
inblock.gif                                        
case "1":
inblock.gif                                            highlight(Ext.query(
'li:first'"extdt"));
inblock.gif                                        
break;
inblock.gif                                        
case "2":
inblock.gif                                            highlight(Ext.query(
'li:even'"extdt"));
inblock.gif                                        
break;
inblock.gif                                        
case "3":
inblock.gif                                            highlight(Ext.query(
'li'"extdt").splice(0,3));
inblock.gif                                        
break;
inblock.gif                                        
case "4":
inblock.gif                                            highlight(Ext.query(
'li:not(.goofy)'"extdt"));
inblock.gif                                        
break;
inblock.gif                                        
case "5":
inblock.gif                                            highlight(Ext.query(
'p a[href*=#]'"extdt"));
inblock.gif                                        
break;
inblock.gif                                        
case "6":
inblock.gif                                            highlight(Ext.query(
'code, li.goofy'"extdt"));
inblock.gif                                        
break;
inblock.gif                                        
case "7":
inblock.gif                                            highlight(Ext.query(
'ul .goofy > strong'"extdt"));
inblock.gif                                        
break;
inblock.gif                                        
case "8":
inblock.gif                                            highlight(Ext.query(
'li+li>a[href$=pdf]'"extdt"));
inblock.gif                                        
break;
inblock.gif                                        
case "9":
expandedsubblockstart.gifcontractedsubblock.gif                                            
if (Ext.query("span{display=none}""extdt").length > 0dot.gif{
inblock.gif                                                highlightHidden( Ext.query(
"span{display=none}""extdt") );    
expandedsubblockstart.gifcontractedsubblock.gif                                            }
else dot.gif{
inblock.gif                                                highlightHidden( Ext.query(
"span{display}""extdt"));
expandedsubblockend.gif                                            }

inblock.gif 
inblock.gif                                        
break;
inblock.gif                                        
case "10":
inblock.gif                                            highlight( Ext.query(
"li:nth(4)""extdt") );
inblock.gif                                        
break;
expandedsubblockend.gif                                    }

expandedsubblockend.gif                                }
(id);
expandedsubblockend.gif                            }

expandedsubblockstart.gifcontractedsubblock.gif                            
if (e == "x")dot.gif{
inblock.gif 
expandedsubblockend.gif                            }

expandedsubblockend.gif                        }

inblock.gif                    );
expandedsubblockend.gif                }

expandedsubblockend.gif            }

expandedsubblockend.gif        }
();
inblock.gif 
inblock.gif        Ext.onReady(
expandedsubblockstart.gifcontractedsubblock.gif            
function()dot.gif{
inblock.gif                domquery.init();
expandedsubblockend.gif            }

inblock.gif        );    
expandedblockend.gif        
</ script >
none.gif 
none.gif        
< div  style ="border: 1px solid rgb(0, 0, 0); padding: 1em; width: 400px;"  id ="extdt" >
none.gif            
< class ="goofy" >  This is a  < em > paragraph </ em >  of  < strong > text </ strong >  with class=”goofy.” It has an  < title ="http://www.englishrules.com"  class ="external text"  href ="http://www.englishrules.com" > external link </ a > , some  < code > $(code) </ code > , and a  < title =""  href ="#dt-link3_same-page_link" > #dt-link3 same-page link </ a > </ p >
none.gif            
< ul >
none.gif                
< li > list item 1 with dummy link to
none.gif                    
< title ="Silly.pdf"  class ="new"  href ="/action/edit/Silly.pdf" > silly.pdf </ a >
none.gif                
</ li >
none.gif                
< li  class ="goofy" >
none.gif                    
< em > list  < strong > item </ strong >  2 </ em >  with class=” < strong > goofy </ strong >
none.gif                
</ li >
none.gif                
< li  > list item 3
none.gif                    
< span  style ="display:none;" >  SURPRISE! </ span >
none.gif                
</ li >
none.gif                
< li >
none.gif                    
< strong > list item 4 </ strong >  with silly link to
none.gif                    
< title ="Silly.pdf silly.pdf"  class ="new"  href ="/action/edit/Silly.pdf_silly.pdf" > silly.pdf silly.pdf </ a >
none.gif                
</ li >
none.gif            
</ ul >
none.gif        
</ div >
none.gif 
none.gif        
< div  class ="dom-traversal-toggles" >
none.gif            
< ul >
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link1"   />   < code > Ext.query('li:first') </ code >  gets the first list item </ li >
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link2"   />   < code > Ext.query('li:even') </ code >  gets all odd-numbered list items (because, in javascript, numbering starts with 0, not 1). </ li >
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link3" />   < code > Ext.query('li').splice(0,3) </ code >  gets the first 3 list items. “lt” stands for “less than,” and it starts counting at 0, not 1.  </ li >
none.gif 
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link4" />   < code > Ext.query('li:not(.goofy)') </ code >  gets list items 1, 2, and 4, because they’re not “goofy.” </ li >
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link5" />   < code > Ext.query('p a[href*=#]') </ code >  gets any links that are inside a paragraph and have an “href” attribute containing “#” anywhere. </ li >
none.gif 
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link6" />   < code > Ext.query('code, li.goofy') </ code >  gets all code elements  < em > and </ em >  any list item with a class of “goofy.” </ li >
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link7" />   < code > Ext.query('ul .goofy > strong') </ code >  gets all strong elements that are children of any element with a class of “goofy” as long as the class somewhere inside (i.e. a descendent) of an ordered list. Notice that the word “item” is not highlighted because, even though it’s inside “.goofy,” it’s not a direct child. Only “goofy” is a direct child of “.goofy.” Maybe we should call it “goofy jr.”  </ li >
none.gif 
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link8" />   < code > Ext.query('li + li > a[@href$=pdf]') </ code >  gets all links ending in “pdf” that are children of any list item that has another list item as its previous sibling. It won’t get the first list item’s silly.pdf because that list item has no other list items before it. </ li >
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link9" />   < code > Ext.query("span{display=none}") </ code >  gets any span element that is hidden. </ li >
none.gif                
< li >< input  type ="submit"  value ="toggle"  id ="dt-link10" />   < code > Ext.query("li:nth(4)") </ code >  gets the 4th li element </ li >
none.gif 
none.gif            
</ ul >
none.gif        
</ div >
none.gif    
</ body >
none.gif
</ html >
none.gif

最后

以上就是老实曲奇为你收集整理的DomQuery v1.1 高级Tutorial:DomQuery v1.1 Advanced的全部内容,希望文章能够帮你解决DomQuery v1.1 高级Tutorial:DomQuery v1.1 Advanced所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部