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 鴻雁 閱讀(900) 評論(0)  編輯  收藏 所屬分類: IT技術相關

          主站蜘蛛池模板: 鸡泽县| 康马县| 波密县| 宁津县| 水富县| 友谊县| 德阳市| 盘锦市| 宁城县| 民勤县| 泽普县| 财经| 平泉县| 沙河市| 兖州市| 浦城县| 渑池县| 建昌县| 梨树县| 离岛区| 天全县| 政和县| 满城县| 西充县| 清流县| 柯坪县| 长泰县| 嘉义市| 建始县| 汽车| 马鞍山市| 托克逊县| 邹平县| 永善县| 五台县| 当涂县| 儋州市| 获嘉县| 福泉市| 梁平县| 乃东县|