The important thing in life is to have a great aim , and the determination

常用链接

统计

IT技术链接

保险相关

友情链接

基金知识

生活相关

最新评论

js合并指定列值重复的单元格

     function uniteTab(tableId,col) {
     //col-- 需要合并单元格的列 1开始
       var tb=document.getElementById(tableId);
       tb.style.display='';
        var i = 0;
        var j = 0;
        var rowCount = tb.rows.length; //   行数 
        var colCount = tb.rows[0].cells.length; //   列数 
        var obj1 = null;
        var obj2 = null;
        //为每个单元格命名 
        for (i = 0; i < rowCount; i++) {
            for (j = 0; j < colCount; j++) {
                tb.rows[i].cells[j].id = "tb__" + i.toString() + "_" + j.toString();
            }
        }
        //合并行 
        for (i = 0; i < colCount; i++) {
            if (i == colLength) break;
            obj1 = document.getElementById("tb__0_" + i.toString())
            for (j = 1; j < rowCount; j++) {
                obj2 = document.getElementById("tb__" + j.toString() + "_" + i.toString());
                if (obj1.innerText == obj2.innerText) {
                    obj1.rowSpan++;
                    obj2.parentNode.removeChild(obj2);
                } else {
                    obj1 = document.getElementById("tb__" + j.toString() + "_" + i.toString());
                }
            }
        }
        //合并列
        for (i = 0; i < rowCount; i++) {
            colCount = tb.rows[i].cells.length;
            obj1 = document.getElementById(tb.rows[i].cells[0].id);
            for (j = 1; j < colCount; j++) {
                if (j >= colLength) break;
                if (obj1.colSpan >= colLength) break;

                obj2 = document.getElementById(tb.rows[i].cells[j].id);
                if (obj1.innerText == obj2.innerText) {
                    obj1.colSpan++;
                    obj2.parentNode.removeChild(obj2);
                    j = j - 1;
                }
                else {
                    obj1 = obj2;
                    j = j + obj1.rowSpan;
                }
            }
        }
    }

posted on 2013-07-06 15:09 鸿雁 阅读(742) 评论(0)  编辑  收藏 所属分类: IT技术相关


只有注册用户登录后才能发表评论。


网站导航: