Js to the table td for the same content merge example

  • 2020-03-30 01:05:55
  • OfStack

 
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=="#00FFFF"){ 
ys="#EEEE00"; 
}else{ 
ys="#00FFFF"; 
} 
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="#00FFFF";// Change color 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, the last few lines are the same case
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]); 
} 
} 
} 
} 

Related articles: