Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>js Dynamic Action Table </title>
<script language= "JavaScript" >
function init () {
_table=document.getelementbyid ("table");
_table.border= "1px";
_table.width= "800px";
for (Var i=1;i<6;i++) {
var row=document.createelement ("tr");
Row.id=i;
for (Var j=1;j<6;j++) {
var cell=document.createelement ("TD");
cell.id=i+ "/" +J;
Cell.appendchild (document.createTextNode ("+cell.id+"));
Row.appendchild (cell);
}
document.getElementById ("Newbody"). appendchild (row);
}
}
function Rebulid () {
var Beginrow=document.getelementbyid ("Beginrow"). value;/* Start Line * *
var Endrow=document.getelementbyid ("Endrow"). value;/* End Line * *
var Begincol=document.getelementbyid ("Begincol"). value;/* Start Column * *
var Endcol=document.getelementbyid ("Endcol"). value;/* End Column */
var tempcol=beginrow+ "/" +begincol;/* locate the column to which you want to change the property.
alert (Tempcol);
var Td=document.getelementbyid (Tempcol);
for (Var x=beginrow;x<=endrow;x++) {
for (Var i=begincol;i<=endcol;i++) {
if (X==beginrow) {
document.getElementById ("table"). Rows[x].deletecell (i+1);
}
else{
document.getElementById ("table"). Rows[x].deletecell (i);
}
}
}
Td.rowspan= (Endrow-beginrow) +1;
}
/* Add line, use AppendChild method * *
function AddRow () {
var Length=document.getelementbyid ("table"). Rows.length;
/*document.getelementbyid ("Newbody"). InsertRow (length);
document.getElementById (length+1). setattribute ("id", length+2);
var tr=document.createelement ("tr");
tr.id=length+1;
var td=document.createelement ("TD");
for (i=1;i<4;i++) {
Td.id=tr.id+ "/" +i;
Td.appendchild (document.createTextNode ("+td.id+"));
Tr.appendchild (TD);
}
document.getElementById ("Newbody"). appendchild (TR);
}
function Addrow_withinsert () {
var Row=document.getelementbyid ("table"). InsertRow (document.getElementById ("table"). Rows.length);
var Rowcount=document.getelementbyid ("table"). Rows.length;
var Countcell=document.getelementbyid ("table"). Rows.item (0). Cells.length;
for (Var i=0;i<countcell;i++) {
var Cell=row.insertcell (i);
Cell.innerhtml= "new" + (ROWCOUNT) + "/" + (i+1) + "column";
Cell.id= (ROWCOUNT) + "/" + (i+1);
}
}
/* Delete line, using DeleteRow (Row Index) * *
function Removerow () {
document.getElementById ("Newbody"). DeleteRow (document.getElementById document.getElementById ("table"). rows.length). RowIndex);
}
/* Add column, using Insertcell (column position) method * *
function Addcell () {
/*document.getelementbyid ("table"). Rows.item (0). cells.length
The number of columns used to get the table
*/
For (Var I=0;i<document.getelementbyid ("table"). rows.length;i++) {
var Cell=document.getelementbyid ("table"). Rows[i].insertcell (2);
Cell.innerhtml= "The first" + (i+1) + "/" +3+ "column";
}
}
/* Delete column, using Deletecell (column position) method * *
function Removecell () {
For (Var I=0;i<document.getelementbyid ("table"). rows.length;i++) {
document.getElementById ("table"). Rows[i].deletecell (0);
}
}
</script>
<body onload= "Init ();" >
<table id= "table" align= "Center" >
<tbody id= "Newbody" ></tbody>
</table>
<div>
<table width= "800px" border= "1px" align= "Center" >
<TR><TD align= "center" ><input type= "button" id= "AddRow" name= "AddRow" onclick= "AddRow ();" value= "Add Line" /></TD><TD align= "Center" ><input type= button "id=" Delrow "name=" Delrow "onclick=" Removerow (); " value= "Delete Rows"/></td></tr>
<TR><TD align= "Center" ><input type= button "id=" Delcell "name=" Delcell "onclick=" Removecell (); "Value = "Delete Column"/></TD><TD align= "center" ><input type= "button" id= "Addcell" name= "Addcell" onclick= "AddCell" (); "value= add Column"/></td></tr>
<TR><TD align= "center" colspan= "2" ><input type= "button" id= "Addrows" name= "Addrows" onclick= "AddRow_" Withinsert (); "value= Add Rows"/></td></tr>
</table>
</div>
<div>
<table width= "800px" border= "1px" align= "Center" >
<tr><td> from <input type= "text" id= "Beginrow" name= "Beginrow" value= ""/> Line to <input type= "text" name= "Endrow" id= "Endrow" value= "/> Row </td><td rowspan=" 2 "id=" test "><input type=" button "Name=" Hebing " Id= "hebing" value= "combined" onclick= "rebulid ();" /></td></tr>
<tr><td> from <input type= "text" name= "Begincol" id= "Begincol" value= ""/> column to <input type= "text" name= "Endcol" id= "Endcol" value= "/> Column </td></tr>
</table>
</div>
</body>