Javascript operations on Dom controls

Source: Internet
Author: User

The last time I mentioned the ASPNET control, I would like to mention that all the ASPNET controls will be generated by default and depend on something called viewstate, which is both good and bad, you can optimize viewstate based on your own needs, such as directly disabling or compressing viewstate.

In web development, JavaScript is definitely the King language of the client. Through the JS engine, it can operate Dom controls in a browser. How can it operate Dom controls? In fact, it is very simple, just a few steps:

1. Get the DOM control you want to manipulate;

2. assign values to the properties of the control you operate on;

It's that simple. Next, let's take a look at the corresponding explanations.

For example, we now have a div whose ID is div1. We need to hide this Div. What should we do? According to the above ideas, first obtain and then assign values.ProgramAs follows:

 
VaR DIV = Document. getelementbyid ("Div1");If(DIV) {Div. style. Display =False;}
 
Must it be simple? Some people say that this function is too simple. The whole process is the same with events and Ajax.
Below we have a dropdownlist. We need to execute Ajax when selecting an event in dropdownlist;CodeAs follows:
 
<Asp: dropdownlist id ="DDL"Runat ="Server"Onselect ="Ddl_select ()"/>FunctionDdl_select (){VaRSelect =Document. Getelementbyid ("DDL");If(! DDL)Return False;VaRValue = select. Options [select. selectedindex]. value;// This selected item ValueAjax_function (value );}FunctionAjax_function (ID ){// Send a request to the server segment by ID}
Is this simple? It is very simple to straighten out. Now it becomes an annoying question about how to know the attributes of the DOM control. Because there are too many Dom controls and there are many relative control attributes, don't worry, things will always solve. First, we only need to remember the commonly used ones. Second, we can use g. Third, we can download the relevant help documentation, or we can also use msdn, which is only in English, here we recommend a CHM document called "DHTML Manual (Lemon)", which can be downloaded. It is basically a lot of Chinese, because it is also quite simple and can be understood by everyone, there are also examples, but the home medicine for web development! What will I talk about next? It seems that the Web Front-end is enough for program developers ?! Let's talk about the next thing!

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.