Dynamically create a client control [add to favorites]

Source: Internet
Author: User

There are currently two popular methods to dynamically operate client controls,
One is innerhtml. This method is understandable and can accomplish tasks, but I do not recommend this method,
Second, upload Doc ument. createelement (),

For example, there is such a tag in the Web: <Div id = "testdiv"> </div>

We can create a table in Div as follows:

VaR table = invalid argument Doc ument. createelement ("table ");

VaR row1 = invalid argument Doc ument. createelement ("TR ");

VaR cell1 = too many Doc ument. createelement ("TD ");

VaR cell1_value = too many Doc ument. createtextnode ("A test table! ");

Cell1.appendchild (cell1_value );

Row1.appendchild (cell1 );

Table. appendchild (row1 );

Invalid Response Doc ument. getelementbyid ("testdiv"). appendchild (table );

Similarly, when creating other controls, you only need to pay attention to the tags you want to create. For example, when you want to create a select, You need to append option.

When modifying, you must first wnidow.doc ument. getelementbyid and then search for the node to be modified,

1. childnodes [X], locate by serial number

2. nextsibling: Next node of the current node

3. previussibling the previous node of the current node

4. firstchild

5. lastchild
In fact, you can use the following methods to operate some controls on the server, because the controls are sent from the server to the client, the display on the client is based on the most basic html.

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.