Dynamic table generation using JavaScript

Source: Internet
Author: User

Using JavaScript to dynamically generate a table is unavoidable. Because it takes a lot of time to redraw a table. If the window changes, unexpected format changes will occur. So it is best not to use it.

Add a <Div id = 'divtable'> </div> in <form> to use JavaScript code to do this:

Function createtable (divname)

...{

VaR DIV = Document. getelementbyid (divname );
VaR table = Document. createelement ("table"); // create a table
VaR ROW = table. insertrow (); // create a row
VaR cell = table. insertcell (); // create a unit
Cell. width = "10"; // modify cell attributes
Cell. style. backgroundcolor = "#999999 ";
}

 

You can also use your imagination to dynamically create various controls. The above function is placed in the JS file.

If you call <SCRIPT type = "..." src = "*. js"> </SCRIPT>

Here we have created a table element, but it has not been loaded into the DIV layer.

We recommend that you do not use Div. innerhtml or Div. innertext.

Use Div. appendchild (table );

 

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.