How to dynamically add cells !!
CopyCode The Code is as follows: Use the insertrow () and insertcell () Methods
The usage is as follows:
Insertrow ()Copy codeThe Code is as follows: var newtr = tableobj. insertrow (N );
Copy codeThe Code is as follows: where n indicates the number of rows inserted!
Note: When n = 0, insert it to the top row! This parameter is omitted when n =-1 is inserted to the last line!
Insertcell ()
Copy codeThe Code is as follows: var newtd = trobj. insertcell (N );
N indicates the column to which the data is inserted!
Note: When n = 0, insert it to the top row! This parameter is omitted when n =-1 is inserted to the last line!
The following is an example code:Copy codeThe Code is as follows:
<Script language = "JavaScript">
VaR COUNT = false, NO = 1;
Function addrow (){
Count =! Count;
// Add a row
VaR newtr = testtbl. insertrow ();
// Add three columns
VaR newtd0 = newtr. insertcell ();
VaR newtd1 = newtr. insertcell ();
VaR newtd2 = newtr. insertcell ();
// Set the column content and attributes
If (count) {newtr. style. Background = "# ffe1ff ";}
Else {newtr. style. Background = "# ffefd5 ";}
Newtd0.innerhtml = '<input type = checkbox id = "box4"> ';
No ++
Newtd1.innertext = "row" + NO + ";
}
</SCRIPT>
Xmlns = "http://www.w3.org/1999/xhtml">