ExtJSDOM element Operation Experience Sharing _ extjs-js tutorial

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.