The topic of this article is to share some of my experiences in using ExtJS to operate DOM elements. As a programmer, I need to keep learning, friends who like it can learn to remember that they used JQuery to operate DOM elements when they first came into contact with Web pages. After graduation, I was engaged in C ++ programming. Two years later, I solved web programming again. But this time I didn't use JQuery, but I used ExtJS. As far as my experience is concerned, programmers are an industry that requires continuous learning (that's why many colleagues around me have white hair ).
Now, the topic of this article is to share my experience in using ExtJS to operate DOM elements.
How to set the element click Handler
The Code is as follows:
Var elem = Ext. get ('start ');
Elem. on ('click', function (e, t ){
Alert (t. id );
});
Query multiple element operations
The Code is as follows:
Var body = Ext. query ('body') [0];
Body. className = "myStyle ";
In actual projects, because you need to change the information style of a class of elements, if you want to search for them based on css, you cannot continue to search for all elements based on css when you need to disappear. At this time, my colleague taught me a new method, as shown below:
The Code is as follows:
// Multiple elements that belong to the same 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 ";
}
// Set the css style for each element.
ElemMessageArray. each (function (el ){
El. set (newCssObj );
El. update (text );
El. show ("display ");
});
Display and hide Elements
Previously I used this method
The Code is as follows:
Uncompleted = Ext. get ('uncompleted ');
ElemUncompleted. setDisplayed (true );
This method can provide the animation effect. However, if the elements disappear, the elements still occupy the space of the elements, which is inconvenient to layout. Later, my colleagues found that this method could be used. Although there is no animation effect, it does not occupy the element position:
The Code is as follows:
El. show ("display ");
El. hide ("display ");
Description in the document just found:
Hide this element-Uses display mode to determine whether to use "display" or "visibility". See setVisible.
A programmer must read the document carefully!