Add and delete row code instances in HTML table dynamically

Source: Internet
Author: User

<HTML> <br/> <pead> <br/> <title> dynamic table </title> <br/> <MCE: script Type = "text/JavaScript"> <! -- <Br/> function addrow (tbodyid) <br/> {<br/> var bodyobj = document. getelementbyid (tbodyid); <br/> If (bodyobj = NULL) <br/>{< br/> alert ("body of table not exist! "); <Br/> return; <br/>}< br/> var rowcount = bodyobj. rows. length; <br/> var cellcount = bodyobj. rows [0]. cells. length; <br/> var newrow = bodyobj. insertrow (rowcount ++); <br/> for (VAR I = 0; I <cellcount; I ++) <br/>{< br/> var cellhtml = bodyobj. rows [0]. cells [I]. innerhtml; <br/> If (cellhtml. indexof ("NONE")> = 0) <br/>{< br/> cellhtml = cellhtml. replace ("NONE", ""); <br/>}< br/> newrow. insertcell (I ). innerhtml = cellhtml; <br/>}< br/> function removerow (inputobj) <br/>{< br/> If (inputobj = NULL) return; <br/> var parenttd = inputobj. parentnode; <br/> var parenttr = parenttd. parentnode; <br/> var parenttbody = parenttr. parentnode; <br/> parenttbody. removechild (parenttr); <br/>}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <Table> <br/> <tbody id = "tbody1"> <br/> <tr> <br/> <TD> <br/> <input type = "text" size = "40"/> <br/> </TD> <br/> <TD> <br/> <input style = "display: none "mce_style =" display: none "type =" button "value =" delete "onclick =" removerow (this) "/> <br/> </TD> <br/> </tr> <br/> </tbody> <br/> <tr> <br/> <TD> <br/> <input type = "button" value = "add row" onclick = "addrow ('tbody1 ') "/> <br/> </TD> <br/> <TD> </P> <p> </TD> <br/> </tr> <br/> </table> <br/> </body> <br/> </ptml> <br/>

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.