코드: 코드 복사 코드는 다음과 같습니다. <머리> merge.html var totalCol = $("#tbl").find("tr").eq(0).find("td").length; <br>for(var col=totalCol-1;col>=1;col--){ <br>spanNum =1; <br>startCell = $("#tbl").find("tr").eq(totalRow-1).find("td").eq(col); <br>for(var row = totalRow-1;row>=1;row--){ <br>targetCell = $("#tbl").find("tr").eq(row-1).find ("td").eq(col); <br>if(startCell.text() == targetCell.text() && startCell.text()!=""){ <br>spanNum ; <br>targetCell.attr("rowSpan",spanNum); <br>startCell.remove(); <br>}else{ <br>spanNum =1; <br>} <br>startCell = targetCell; <br>} <br>} <br>} <br>function merge2() { //可实现합당并单元格,上下行来比较 <br>var totalCols = $("#tbl").find("tr :eq(0)").find("td").length; <br>var totalRows = $("#tbl").find("tr").length; <br>for ( var i = totalCols-1; i >= 1; i--) { <br>for ( var j = totalRows-1; j >= 1; j--) { <br>startCell = $("#tbl").find("tr").eq(j).find("td").eq(i); <br>targetCell = $("#tbl").find("tr").eq(j - 1).find("td").eq(i); <br>if (startCell.text() == targetCell.text() && targetCell.text() != "") { <br>targetCell.attr("rowSpan", (startCell.attr("rowSpan")= =정의되지 않음)?2:(eval(startCell.attr("rowSpan")) 1)); <br>startCell.remove(); <br>} <br>} <br>} <br>} <br>/*先合并,使用style 的display:none将了隐藏,然后再remove <br>*/ <br>function merge3() { <br>var totalCols = $("#tbl").find("tr:eq(0)").find("td").length; <br>var totalRows = $("#tbl").find("tr").length; <br>for(var col=totalCols-1;col>=1;col--){ <br>spanNum =1; <br>startCell = $("#tbl").find("tr").eq(totalRows-1).find("td").eq(col); <br>for(var row = totalRows-1;row>=1;row--){ <br>targetCell = $("#tbl").find("tr").eq(row-1).find ("td").eq(col); <br>if(startCell.text() == targetCell.text() && startCell.text()!=""){ <br>spanNum ; <br>targetCell.attr("rowSpan",spanNum); <br>startCell.attr("style","visibility:hidden"); <br>// startCell.attr("style","display:none"); <br>}else{ <br>spanNum =1; <br>} <br>startCell = targetCell; <br>} <br>} <br>for(var j=totalCols-1;j>=1;j--){ <br>for(var i=totalRows-1;i>=1;i-- ){ <br>cell = $("#tbl").find("tr").eq(i).find("td").eq(j); <br>if(cell.attr("style")!=정의되지 않음){ <br>if(cell.attr("style")=="visibility:hidden"){ <br>cell.remove(); <br>} <br>} <br>} <br>} <br>} <br>function merge4(){ //与merge3방법类似,目적是看一下 display:none与visibility:hidden的效果区别 <br>var totalCols = $("#tbl").find("tr:eq(0)").find("td").length; <br>var totalRows = $("#tbl").find("tr").length; <br>for(var col=totalCols-1;col>=1;col--){ <br>spanNum =1; <br>startCell = $("#tbl").find("tr").eq(totalRows-1).find("td").eq(col); <br>for(var row = totalRows-1;row>=1;row--){ <br>targetCell = $("#tbl").find("tr").eq(row-1).find ("td").eq(col); <br>if(startCell.text() == targetCell.text() && startCell.text()!=""){ <br>spanNum ; <br>targetCell.attr("rowSpan",spanNum); <br>startCell.attr("style","display:none"); <br>// startCell.attr("style","display:none"); <br>}else{ <br>spanNum =1; <br>} <br>startCell = targetCell; <br>} <br>} <br>for(var j=totalCols-1;j>=1;j--){ <br>for(var i=totalRows-1;i>=1;i-- ){ <br>cell = $("#tbl").find("tr").eq(i).find("td").eq(j); <br>if(cell.attr("style")!=정의되지 않음){ <br>if(cell.attr("style")=="display:none"){ <br>cell.remove(); <br>} <br>} <br>} <br>} <br>}<br> <본문> <머리> 销售时间 裙子 裤子 风衣 鞋子 머리> 8:00-9:00 3 4 9:00-10:00 3 2 5 3 10:00-11:00 3 2 1 11:00-12:00 1 테이블>