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
var elem = Ext.get('start');
elem.on('click', function(e, t) {
alert(t.id);
});
Query multiple element operations
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:
// 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
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:
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!