Copy codeThe Code is as follows:
Function hb (){
Var tab = document. getElementById ("subtable ");
Var maxCol = 3, val, count, start;
Var ys = "";
For (var col = maxCol-1; col> = 0; col --){
Count = 1;
Val = "";
For (var I = 0; I <tab. rows. length; I ++ ){
If (val = tab. rows [I]. cells [col]. innerHTML ){
Count ++;
} Else {
If (count> 1 ){
// Merge
Start = I-count;
If (ys = "#00 FFFF "){
Ys = "# EEEE00 ";
} Else {
Ys = "#00 FFFF ";
}
Tab. rows [start]. cells [col]. rowSpan = count;
Tab. rows [start]. cells [1]. style. backgroundColor = ys; // change the color.
// Ys = "# EEEE00 ";
// Tab. rows [I]. cells [1]. style. backgroundColor = "#00 FFFF"; // change the color to green.
For (var j = start + 1; j <I; j ++ ){//
Tab. rows [j]. cells [col]. style. display = "none ";
Tab. rows [j]. removeChild (tab. rows [j]. cells [col]);
}
Count = 1;
}
Val = tab. rows [I]. cells [col]. innerHTML;
}
}
If (count> 1) {// merge, when the last few rows are the same
Start = I-count;
Tab. rows [start]. cells [col]. rowSpan = count;
For (var j = start + 1; j <I; j ++ ){
Tab. rows [j]. removeChild (tab. rows [j]. cells [col]);
}
}
}
}