zoukankan      html  css  js  c++  java
  • 合并表格

    <html>  
      <head>  
      <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312" />  
      <title>合并表格</title>  
      <script>  
      ///////////////////////////////////////////////  
      //   功能:合并表格  
      //   参数:tb--需要合并的表格ID  
      //   参数:colLength--需要对前几列进行合并,比如,  
      //   想合并前两列,后面的数据列忽略合并,colLength应为2  
      //   缺省表示对全部列合并  
      //   data:   2005.11.6  
      ///////////////////////////////////////////////  
      function   uniteTable(tb,colLength){  
       //   检查表格是否规整  
     if   (!checkTable(tb))   return;  
     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)   return;  
        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());  
         }  
        }  
       }  
      }  
       
      /////////////////////////////////////////  
      //   功能:检查表格是否规整  
      //   参数:tb--需要检查的表格ID  
      //   data:   2005.11.6  
      /////////////////////////////////////////  
      function   checkTable(tb){  
       if   (tb.rows.length==0)   return   false;  
       if   (tb.rows[0].cells.length==0)   return   false;  
       for   (var   i=0;i<tb.rows.length;i++){  
        if   (tb.rows[0].cells.length   !=   tb.rows[i].cells.length)   return   false;  
       }  
       return   true;  
      }  
     
      function SpanGrid(tabObj,colIndex) {
      if(tabObj != null) {
        var i,j;
        var intSpan;
        var strTemp;
        for(var m = 0; m <colIndex; m++ ){
         for(i = 0; i < tabObj.rows.length; i++) {
           intSpan = 1;
           strTemp = tabObj.rows[i].cells[m].innerText;
           for(j = i + 1; j < tabObj.rows.length; j++) {
            if(strTemp == tabObj.rows[j].cells[m].innerText) {
              intSpan++;
              tabObj.rows[i].cells[m].rowSpan  = intSpan;
              tabObj.rows[j].cells[m].style.display = "none";
            } else {
              break;
            }
           }
       i = j - 1;
         }
        }
      }
      }
     
     
      function SpanGrid2(tabObj,colIndex) {
      if(tabObj != null) {
        var i,j;
        var intSpan;
        var strTemp;
        for(i = 0; i < tabObj.rows.length; i++) {
          intSpan = 1;
          strTemp = tabObj.rows[i].cells[m].innerText;
          for(j = i + 1; j < tabObj.rows.length; j++) {
           if(strTemp == tabObj.rows[j].cells[m].innerText) {
             intSpan++;
             tabObj.rows[i].cells[m].rowSpan  = intSpan;
             tabObj.rows[j].cells[m].style.display = "none";
           } else {
             break;
           }
          }
      i = j - 1;
        }
      }
      }
     
      </script>  
      </head>  
       
      <body>  
      <table   width="400"   border="1"   id="table1">  
          <tr>  
              <td>a</td>  
              <td>for</td>  
              <td>100</td>  
              <td>200</td>  
          </tr>  
          <tr>  
              <td>a</td>  
              <td>for</td>  
              <td>100</td>  
              <td>200</td>  
          </tr>  
          <tr>  
              <td>a</td>  
              <td>if</td>  
              <td>100</td>  
              <td>200</td>  
          </tr>  
          <tr>  
              <td>a</td>  
              <td>if</td>  
              <td>300</td>  
              <td>240</td>  
          </tr>  
          <tr>  
              <td>a</td>  
              <td>if</td>  
              <td>320</td>   
              <td>320</td> 
          </tr>
      </table>  
      <br />  
      <input   type="button"   value="合并表格"   onClick="SpanGrid(table1,3)" />
        <input   type="button"   value="合并表格"   onClick="uniteTable(table1,2)" />  
      </body>  
      </html>  


     

    keim,毕业于安徽科技学院理学院,2003年开始对Web开发有浓厚的兴趣,并专注于C#/java Web开发,软件架构设计、分布式相关、项目管理、前端设计等等,实战派...
  • 相关阅读:
    第一个小程序-简单计算器
    You have to be inside an angular-cli project in order to use the serve command.
    执行命令npm install typescript@2.3.1 --save-dev,发现了不得了的东西
    安装gulp或者npm淘宝镜像cnpm时出现错误,proxy was not installed probaly
    @angular/compiler-cli@4.3.6 requires typescript@'>=2.1.0 <2.4.0' but 2.5.2 was found instead.
    The "@angular/compiler-cli" package was not properly installed. Error: TypeError: Cannot read property 'Private' of undefined
    angula安装各种包出现"Please try running this command again as root/Administrator."的解决方法
    The “@angular/compiler-cli” package was not properly installed
    关于angular开发中报错Cannot find module 'webpack/lib/node/NodeTemplatePlugin'问题的解决办法若干
    psql:定位慢查询
  • 原文地址:https://www.cnblogs.com/zqmingok/p/1509356.html
Copyright © 2011-2022 走看看