Dynamically add, modify, and delete html tables.
Bytes
<Html>
Dynamic_table.js Onerror = handleErrvar txt = "" function handleErr (msg, url, l) {txt = "An error exists on this page. \ N "txt + =" error: "+ msg +" \ n "txt + =" URL: "+ url +" \ n "txt + =" line: "+ l +" \ n "txt + =" click "OK" to continue. \ N "alert (txt) return true} function addRow (name, color, size, unit, discount, count, sum) {var bodyObj = document. getElementById ("goods"); if (bodyObj = null) {alert ("Body of Table not Exist! "); Return;} var rowCount = bodyObj. rows. length; // var cellCount = myarray. length; var newRow = bodyObj. insertRow (rowCount ++); newRow. insertCell (0 ). innerHTML = name; newRow. insertCell (1 ). innerHTML = color; newRow. insertCell (2 ). innerHTML = size; newRow. insertCell (3 ). innerHTML = unit; newRow. insertCell (4 ). innerHTML = discount; newRow. insertCell (5 ). innerHTML = count; newRow. insertCell (6 ). innerHTML = sum;} function RemoveRow (tbodyID, row) {var bodyObj = document. getElementById (tbodyID); if (bodyObj = null) {alert ("Body of Table not Exist! "); Return;} var nrow = Number (row); if (nrow <= bodyObj. rows. length) bodyObj. deleteRow (nrow); else alert ("nrow is less. ");} function modifyRow (tbodyID, row, col, newvalue) {var nrow = Number (row); var ncol = Number (col); var bodyObj = document. getElementById (tbodyID); if (bodyObj = null) {alert ("Body of Table not Exist! "); Return;} try {// var tableObj = bodyObj. parentNode; if (nrow <bodyObj. rows. length & ncol <bodyObj. getElementsByTagName ('tr') [nrow]. getElementsByTagName ('td '). length) {// This may not work on google in ie. // bodyObj. rows (nrow ). cells (ncol ). innerHTML = newvalue; // bodyObj. rows [nrow]. childNodes [ncol]. innerHTML = newvalue; // This document can be used in both ie and google. getElementById (tbodyID ). getElementsByTagName ('tr') [nrow]. get ElementsByTagName ('td ') [ncol]. innerHTML = newvalue;} else alert ("empty. ");} catch (err) {alert (err. description) ;}} function clearRows (tbodyID) {var bodyObj = document. getElementById (tbodyID); if (bodyObj = null) {alert ("Body of Table not Exist! "); Return ;}for (var I = 0; I <bodyObj. rows. length;) bodyObj. deleteRow (I );}
Run normally under win7 ie10 and google 4. note 1. it is recommended that you do not use the notepad that comes with windows. There will be encoding problems. We recommend using notepad ++, encoding utf8 without bom2. some js functions will be available in ie and unavailable in google, this code is generic Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.