Use js to dynamically operate tables (add and delete related column information)

Source: Internet
Author: User
1. Get the table object
VaR objtable = Document. getelementbyid ("tb_visitor ");
2. Add a row
VaR objtemprow = objtable. Rows [0]; // obtain the template row.
VaR objnewrow = objtable. insertrow (objtable. Rows. Length );
Objnewrow. ID = objtable. Rows. Length-1;
// Add information about a row
For (VAR I = 0; I <objtemprow. cells. length; I ++)
{
VaR objnewcell = objnewrow. insertcell (I );
Objnewcell. innerhtml = objtemprow. cells [I]. innerhtml;
//
If (objnewcell. innerhtml. indexof ("value = ")! =-1 ){
VaR Si = objnewcell. innerhtml. indexof ("value =") * 1 + 6;
VaR Ei = objnewcell. innerhtml. indexof ("> ");
VaR cellvalue = objnewcell. innerhtml. substring (Si, EI );
// Clear the content of the new column and make it available
Objnewcell. innerhtml = objnewcell. innerhtml. Replace (cellvalue, ''). Replace ('Disabled ','');
}
}
// Click the row to be added
Objnewrow. onclick = new function ("fn_clickrow (this );");
3. delete a row
Objtable. deleterow (objrow. Index );

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.