The following code I tested in IE, Firefox, Chrome all through
<title> New Document </title>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<script type= "Text/javascript" >
function Rdl_doadd () {
var filetable = document.getElementById (' filelist ');
var tr = document.createelement (' tr ');
var td1 = document.createelement (' TD ');
td1.innerhtml = ' 111 ';
var td2 = document.createelement (' TD ');
td2.innerhtml = ' 222 ';
Tr.appendchild (TD1);
Tr.appendchild (TD2);
Filetable.appendchild (TR);
}
</script>
<body>
<table cellspacing=1 id=mytable width=90%>
<tbody id= "FileList" >
</table>
<br><input Type=button value= "Insert Tbody" onclick= "Rdl_doadd ();" >
</body>
It should be noted that <table> must have <tbody> otherwise it will not work under the IE6. The reasons are said to be as follows:
Under IE COL, Colgroup, FRAMESET, HTML, STYLE, TABLE, Tbody, TFOOT, THEAD, TITLE, TR the InnerHTML properties of these elements are read-only and cannot be manipulated directly.
Originally directly using the InsertRow () method in IE no problem, but Firefox and Chrome has no effect, online said to change to InsertRow (-1), but I still do not
var TB = document.getElementById ("DataTable");
tb.rows[1].cells[1].innerhtml = "zzzzzz";
Number of table rows
var rownum = tb.rows.length;
Number of columns
var cownum = tb.rows.item (0). Cells.length;
Add a row
var newtr = Tb.insertrow ();
Adding columns
for (i=0;i<3;i++) {
var Mytd=mytr.insertcell ();
Mytd.innertext= "The first" + (i+1). toString () + "cells";
}
Reference: http://www.jb51.net/article/19708.htm