Home > Web Front-end > JS Tutorial > body text

ExtJS DOM element manipulation experience sharing_extjs

WBOY
Release: 2016-05-16 17:24:10
Original
981 people have browsed it

I remember that the first time I came into contact with operating DOM elements on a web page was when I was doing my graduation project, and I used JQuery to do it. After graduation, I was engaged in C programming. Two years later, I tackled web programming again, but this time I used ExtJS instead of JQuery. From my experience, programmers are an industry that requires continuous learning (which is why many colleagues around me have gray hair).

Okay, the topic of today’s article is to share some of my experience using ExtJS to manipulate DOM elements.
How to set the element click processing function

Copy the code The code is as follows:

var elem = Ext.get('start');

elem.on('click', function(e, t) {
alert(t.id);
});

Query multiple element operations
Copy code The code is as follows:

var body = Ext.query('body')[0];
body.className = "myStyle";

In the actual project, due to the need to change the information prompt style of a type of element, If you search based on css, when the disappearing operation is needed, you cannot continue to search for all elements based on css. At this time, my colleague taught me a new method, as follows:
Copy code The code is as follows:




// Multiple elements that also belong to the group can be obtained in this way:
var elemMessageArray = Ext.select("span[ group='message_group']");

var newCssObj = {};

if (isInfo) {
newCssObj["class"] = "info";
} else {
newCssObj["class"] = "error";
}

// Then just reset the css style for each element
elemMessageArray.each( function(el) {
el.set(newCssObj);
el.update(text);
el.show("display");
});

element Showing and hiding

The way I usually used before
Copy the code The code is as follows:

Uncompleted = Ext.get('uncompleted');
elemUncompleted.setDisplayed(true);

This method can provide animation effects, but in this case, if the element needs to disappear : Although the element disappears, it still occupies the element's space, making layout inconvenient. Later, colleagues discovered that this method can be used. Although there is no animation effect, it will not occupy the position of the element:
Copy code The code is as follows:

el.show("display");
el.hide("display");

I just found the instructions in the document:

Hide this element - Uses display mode to determine whether to use "display" or "visibility". See setVisible.

Reading the documentation carefully is what programmers must learn to do!
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!