因为前面的列已经合并掉了,不见了,所以每次只找0开始的列就好了

解决方案 »

  1.   


    <script type="text/javascript">
    function mc(tableId, startRow, endRow, col) {
    var tb = document.getElementById(tableId);
    if (col >= tb.rows[0].cells.length-0) {
    return;
    }
    if (col == 0) {
    endRow = tb.rows.length - 1;
    }
    for (var i = startRow; i < endRow; i++){
    var subCol = tb.rows[0].cells.length - tb.rows[startRow].cells.length;
    if (tb.rows[startRow].cells[col-subCol].innerHTML == tb.rows[i + 1].cells[0].innerHTML) {
    tb.rows[i + 1].removeChild(tb.rows[i + 1].cells[0]);
    tb.rows[startRow].cells[col-subCol].rowSpan = (tb.rows[startRow].cells[col-subCol].rowSpan | 0) + 1;
    if (i == endRow - 1 && startRow != endRow) {
    mc(tableId, startRow, endRow, col + 1);
    }
    } else {
    mc(tableId, startRow, i + 0, col + 1);
    startRow = i + 1;
    }
    }
    }
    mc('table1', 0, 0, 0); 
    </script>
      

  2.   

    确实是,你真是帮了我的大忙了 ,太谢谢你了