zoukankan      html  css  js  c++  java
  • 通用表格合并单元格

    1.源码: 

    /**

     * 合并表格的列
     * @param {String} tableId要合并的表格的id
     * @param {int} fCol开始的列
     * @param {int} eCol结束的列
     * @return void
     */
    function mergCol(tableId, fCol, eCol) {

    var oTable = document.getElementById(tableId);
    if (!oTable) {
    return;
    }

    var oTBody = oTable.tBodies[0];
    var oRows = oTBody.rows;
    if (oRows.length == 0) {
    return;
    }
    var rowspan = 1;
    for ( var j = fCol; j <= eCol; j++) {
    var oRow = oRows[0];
    for ( var i = 1; i < oRows.length; i++) {
    var oNextRow = oRows[i];
    if ((oRow.cells[j] != null && oNextRow.cells[j] != null)
    && (oRow.cells[j].innerHTML == oNextRow.cells[j].innerHTML)) {
    rowspan++;
    oRow.cells[j].merg = rowspan;
    oNextRow.cells[j].merg = -1;
    } else {
    oRow = oNextRow;
    rowspan = 1;
    }
    }
    }
    for ( var i = oRows.length - 1; i >= 0; i--) {
    for ( var j = eCol; j >= fCol; j--) {
    var oRow = oRows[i];
    if (oRow.cells[j] != null && oRow.cells[j].merg == -1) {
    oRow.cells[j].parentNode.removeChild(oRow.cells[j]);
    } else {
    if (oRow.cells[j] != null && oRow.cells[j].merg > 0) {
    oRow.cells[j].rowSpan = oRow.cells[j].merg;
    }
    }
    }
    }
    }

    应用:mergCol ('edit-0',0,0);

     
  • 相关阅读:
    aspx有"记住我"的登录
    Aspx比较简单的登录
    内容显示分页数字分页 aspx
    Ashx登录
    Aspx 验证码_各种封装
    IsPostBack的使用
    Ashx增删改查_动软
    一般处理程序ashx
    dispatch_after
    pch文件的作用
  • 原文地址:https://www.cnblogs.com/nxblog/p/4200696.html
Copyright © 2011-2022 走看看