JavaScript dynamically added ranks

Source: Internet
Author: User

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

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.