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

          主站蜘蛛池模板: 江陵县| 蚌埠市| 闽侯县| 织金县| 静宁县| 临颍县| 沧源| 洪湖市| 古浪县| 瑞安市| 蒲江县| 巴中市| 柞水县| 克什克腾旗| 沐川县| 沂源县| 绥棱县| 军事| 普兰县| 北碚区| 巨野县| 壶关县| 砚山县| 偃师市| 长春市| 防城港市| 永胜县| 抚顺县| 双峰县| 红桥区| 利辛县| 望谟县| 邢台市| 安图县| 宁明县| 河池市| 称多县| 河曲县| 公主岭市| 峡江县| 济阳县|