Add rows in the complete Table operation of javescript and delete the columns of rows. _ javascript skills

Source: Internet
Author: User
Very nice js operations for table row code functions. Convenient

<HTML> <TITLE> Form Object example </TITLE> <HEAD> <script language = "javascript"> function delrow1 () {var oElement = event. srcElement; while (oElement. tagName! = "TR") {oElement = oElement. parentElement;} var oTBody = oElement. parentElement; oTBody. removeChild (oElement)} function delrow2 () // except the current row {var currRowIndex = event. srcElement. parentNode. parentNode. rowIndex; document. all. yltable. deleteRow (currRowIndex); // table10 -- table id} function insertrow1 () // Add a row of method 1 {var newnode = document. getElementById ('ltable '). lastChild. cloneNode (true); document. getElementById ('ltable '). appendChild (newnode);} function insertrow2 () // Add a row of method 2 {newRow = document. all. yltable. insertRow (-1); var j_1 = document. all. yltable. rows. length; newcell = newRow. insertCell (); newRow. bgColor = '# ffff'; newcell. align = 'center'; newcell. innerHTML = "" + j_1 + ""; newcell = newRow. insertCell (); newRow. bgColor = '# ffff'; newcell. align = 'center'; newcell. innerHTML = "<input type = 'text' name = 'yltext" + j_1 + "'/>"; newcell = newRow. insertCell (); newRow. bgColor = '# ffff'; newcell. align = 'center'; newcell. innerHTML = '<input name = "button3" type = "button" onClick = "delrow1 () "value =" delete 1 "> <input name =" button3 "type =" button "onClick =" delrow2 () "value =" Delete 2 "> '; document. all. yltable. focus ();} function inserttable () {var newnode = document. getElementById ('ltable '). cloneNode (true); document. getElementById ('ylform '). appendChild (newnode);} script </HEAD> <BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.