<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> merge tables </title>
<Script>
//////////////////////////////////////// ///////
// Function: Merge tables
// Parameter: tb-ID of the table to be merged
// Parameter: colLength -- the first few columns need to be merged, for example,
// If you want to merge the first two columns, ignore the merging of the following data columns. colLength should be 2
// Merge all columns by default
// Data: 2011.11.06
//////////////////////////////////////// ///////
Function uniteTable (tb, colLength ){
// Check whether the table is regular
If (! CheckTable (tb) return;
Var I = 0;
Var j = 0;
Var rowCount = tb. rows. length; // number of rows
Var colCount = tb. rows [0]. cells. length; // Number of Columns
Var obj1 = null;
Var obj2 = null;
// Name each cell
For (I = 0; I <rowCount; I ++ ){
For (j = 0; j <colCount; j ++ ){
Tb. rows [I]. cells [j]. id = "tb _" + I. toString () + "_" + j. toString ();
}
}
// Check and merge by Column
For (I = 0; I <colCount; I ++ ){
If (I = colLength) return;
Obj1 = document. getElementById ("tb _ 0 _" + I. toString ())
For (j = 1; j <rowCount; j ++ ){
Obj2 = document. getElementById ("tb _" + j. toString () + "_" + I. toString ());
If (obj1.innerText = obj2.innerText ){
Obj1.rowSpan ++;
Obj2.parentNode. removeChild (obj2 );
} Else {
Obj1 = document. getElementById ("tb _" + j. toString () + "_" + I. toString ());
}
}
}
}
/////////////////////////////////////////
// Function: Check whether the table is regular
// Parameter: tb -- ID of the table to be checked
// Data: 2011.11.06
/////////////////////////////////////////
Function checkTable (tb ){
If (tb. rows. length = 0) return false;
If (tb. rows [0]. cells. length = 0) return false;
For (var I = 0; I <tb. rows. length; I ++ ){
If (tb. rows [0]. cells. length! = Tb. rows [I]. cells. length) return false;
}
Return true;
}
</Script>
</Head>
<Body>
<Table width = "400" border = "1" id = "table1">
<Tr>
<Td> a </td>
<Td> for </td>
<Td> 100 </td>
<Td> 200 </td>
<Td> 1 </td>
</Tr>
<Tr>
<Td> a </td>
<Td> for </td>
<Td> 100 </td>
<Td> 300 </td>
<Td> 2 </td>
</Tr>
<Tr>
<Td> a </td> www.2cto.com
<Td> if </td>
<Td> 100 </td>
<Td> 200 </td>
<Td> 3 </td>
</Tr>
<Tr>
<Td> a </td>
<Td> if </td>
<Td> 300 </td>
<Td> 230 </td>
<Td> 4 </td>
</Tr>
<Tr>
<Td> a </td>
<Td> if </td>
<Td> 320 </td>
<Td> 230 </td>
<Td> 5 </td>
</Tr>
</Table>
<Br> <input type = "button" value = "MERGE table" onClick = "uniteTable (table1, 4)">
</Body>
</Html>,
From crawling forward