& Lt; html & gt; & lt; head & gt; & lt; metahttp-equiv & quot; Content-Type & quot; content & quot; text/html; charsetgb2312 & quot; & gt; & lt; title & gt; merge the table & lt;/title & gt; & lt; script & gt ;///
Merge tables
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
For (j = 0; j
Tb. rows [I]. cells [j]. id = "tb _" + I. toString () + "_" + j. toString ();
}
}
// Check and merge by Column
For (I = 0; I
If (I = colLength) return;
Obj1 = document. getElementById ("tb _ 0 _" + I. toString ())
For (j = 1; 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
If (tb. rows [0]. cells. length! = Tb. rows [I]. cells. length) return false;
}
Return true;
}
Script
| A |
For |
100 |
200 |
1 |
| A |
For |
100 |
300 |
2 |
| A | Www.2cto.com
If |
100 |
200 |
3 |
| A |
If |
300 |
230 |
4 |
| A |
If |
320 |
230 |
5 |
,
From crawling forward