Home Web Front-end JS Tutorial Ext.get() and Ext.query() are used in combination to achieve the most flexible way of fetching elements_jquery

Ext.get() and Ext.query() are used in combination to achieve the most flexible way of fetching elements_jquery

May 16, 2016 pm 06:01 PM

I have omitted the parameters for get() and query() written earlier. Let’s take a look at the function prototype in the document first:
Ext.get( Mixed el ) : Element
Parameters:
el : Mixed
The id of the node, a DOM Node or an existing Element.
Returns:
Element
The Element object
Ext.query( String path, [Node root] ) : Array
Parameters:
path : String
The selector/xpath query
root : Node
(optional) The start of the query (defaults to document).
Returns:
Array
The query function actually returns an array of DOM Node, and the parameter el of Ext.get can be a DOM Node, haha, do you understand? That is to say, to achieve the most flexible retrieval method, you should use query to obtain the DOM Node and then hand it to get to turn it into an Element. That is:
var x=Ext.query(QueryStr);
//Why don’t I write it as an inline function? Because x here can only be one element, and x in the above sentence is an Array, you can convert and process it yourself
var y=Ext.get(x);
Then the format of QueryStr needs to be introduced next (In fact, it is very similar to the format of the selector in jQuery). As for what you can do after obtaining the Element, you can read the description of Ext.Element in the ExtJS document for yourself. I will not extract it.
First give me an html code for demonstration purposes

Copy the code The code is as follows:




I'm a div ==> my id: bar, my class: foo
I'm a span within the div with a foo class
An ExtJs link


my id: foo, my class: bar

I'm a P tag within the foo div


I'm a span within the div with a bar classAn internal link

BlueLotus7@126.com


(1) Take according to the tag: // This query will return an array with two elements because the query selects the entire All span tags of the document.
Ext.query("span");
// This query will return an array with one element because the query takes into account the id foo.
Ext.query("span", "foo"); // This will return an array with one element, the content is the p tag under the div tag
Ext.query("div p");
// This will return an array with two elements, the content is the span tag under the div tag
Ext.query("div span"); (2) Based on ID: // This query will return the content containing our foo div an array of elements!
Ext.query("#foo"); //Or directly Ext.get("foo");(3) Get it according to the name of the class: Ext.query(".foo");//This query Will return an array of 5 elements.
Ext.query("*[class]"); // Result: [body#ext-gen2.ext-gecko, div#bar.foo, span.bar, div#foo.bar, span.bar] (4) Universal method to get: (You can use this method to get by id, name, class, css, etc.) // This will get all the elements whose class is equal to "bar"
Ext.query("*[class=bar" ]");
// This will get all elements whose class is not equal to "bar"
Ext.query("*[class!=bar]");
// This will get the class from " All elements starting with b"
Ext.query("*[class^=b]");
//This will get all elements whose class ends with "r"
Ext.query( "*[class$=r]");
//This will get all elements that extract the "a" character in class
Ext.query("*[class*=a]");// This will get all elements with name equal to "BlueLotus7"
Ext.query("*[name=BlueLotus7]");
Let's change the html code:
Copy code The code is as follows:






I am a div ==> My id is: bar, my class: foo
I'm a span within the div with a foo class
An ExtJs link with a blank target!


my id: foo, my class: bar

I'm a P tag within the foo div


I'm a span within the div with a bar class
An internal link




// Get all red elements
Ext.query("*{color=red}"); // [div#bar.foo]
// Get all pink elements with red color Elements of child elements
Ext.query("*{color=red} *{color=pink}"); // [span.bar]
// Get all elements that are not red text
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#]
// Get all elements whose color attribute starts from "yel"
Ext.query("*{color^=yel}"); // [a www.extjs.com]
// Get all elements whose color attributes end with "ow"
Ext.query( "*{color$=ow}"); // [a www.extjs.com]
// Get all elements whose color attribute contains the "ow" character
Ext.query("*{color*= ow}"); // [a www.extjs.com, span.bar]
(5) Change the pseudo operator method to html:
Copy code The code is as follows:





< ;div id="bar" class="foo" style="color:red; border: 2px dotted red; margin:5px; padding:5px;">
I am a div ==> my id It's bar, and my class is foo
Here is the span element, and the outer div element has the class attribute of foo
Set blank=target ExtJS link
< /div>

The id here is : foo, the class here is the p element surrounded by bar

"foo" div.


Here is a span element, surrounded by divs on the outer layer, and span also has a class attribute of bar.
Built-in link



  • Item #1

  • Item #2
  • Item #3

  • Item #4 with Link













First line , the first column The first row, the second column
The second row, cells have been merged!
Third row, first column Third row, Second column








//The SPAN element is the first child element of its parent element
Ext.query("span:first-child"); // [span.bar]
//The A element is its parent The last child element of the element
Ext.query("a:last-child") // [a www.extjs.com, a test.html#]
//The SPAN element is the third of its parent element 2 child elements (number starting from 1)
Ext.query("span:nth-child(2)") // [span.bar]
//TR element is an odd number of its parent element Number of child elements
Ext.query("tr:nth-child(odd)") // [tr, tr]
//LI element is an odd number of child elements of its parent element
Ext.query("li:nth-child(even)") // [li, li]
//Returns the A element, which is the only child element of its parent element
Ext.query("a :only-child") // [a test.html#]
//Return all checked (checked) INPUT elements
Ext.query("input:checked") // [input#chked on ]
//Return the first TR element
Ext.query("tr:first") // [tr]
//Return the last INPUT element
Ext.query(" input:last") // [input#notChked on]
//Return the second TD element
Ext.query("td:nth(2)") // [td]
/ /Return each DIV containing the "within" string
Ext.query("div:contains(within)") // [div#bar.foo, div#foo.bar]
//Return None Contains those DIVs other than FORM sub-elements
Ext.query("div:not(form)") [div#bar.foo, div#foo.bar, div]
//Returns the A element Those DIV collections
Ext.query("div:has(a)") // [div#bar.foo, div#foo.bar, div]
//Return those TDs that will continue to have TDs gather. One thing in particular is that if TD with the colspan attribute is used, it will be ignored
Ext.query("td:next(td)") // [td, td]
//Return the element that precedes the INPUT Those LABEL element collections
Ext.query("label:prev(input)") //[label, label]
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Can PowerPoint run JavaScript? Can PowerPoint run JavaScript? Apr 01, 2025 pm 05:17 PM

JavaScript can be run in PowerPoint, and can be implemented by calling external JavaScript files or embedding HTML files through VBA. 1. To use VBA to call JavaScript files, you need to enable macros and have VBA programming knowledge. 2. Embed HTML files containing JavaScript, which are simple and easy to use but are subject to security restrictions. Advantages include extended functions and flexibility, while disadvantages involve security, compatibility and complexity. In practice, attention should be paid to security, compatibility, performance and user experience.

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

See all articles