wanglujun0705

          有夢想很偉大,沒有行動很悲劇

           

          IE,谷歌,遨游,火狐兼容的萬能合并單元格方法

          // tb:要合并單元格的表格;stacol:開始合并列;endcol:結束合并列;bool:合并方式(true代表stacol與endcol之間合并;   false代表兩邊和并);num標記列(防止某些信息因為內容相同而合并。eg,姓名相同而編號不同的兩個人)
          02 function   uniteTable(tb,stacol,endcol,bool,num)
          03 {var end;
          04  var   i=0;  
          05  var   j=0;  
          06  var   rowCount=tb.rows.length;         //  行數  
          07  var   colCount=tb.rows[0].cells.length; // 列數  
          08  var   obj1=null;  
          09  var   obj2=null;  
          10  var  n=5;
          11  var count=new Array();
          12  for   (i=0;i<rowCount;i++){  
          13     for   (j=0;j<colCount;j++){  
          14         tb.rows[i].cells[j].id="tb__" + i+"_"+j;      
          15                               }  
          16                             }  
          17       //合并標記列,防止某些信息因為內容相同而合并(不需要時,可以不用傳值)
          18            if(typeof(num)!='undefined'){
          19                   obj1=document.getElementById("tb__0_"+(num-1).toString());  
          20           for(var t=1;t<rowCount;t++){
          21 obj2=document.getElementById("tb__"+t.toString()+"_"+(num-1).toString());                                     
          22       if   (obj1.innerHTML==obj2.innerHTML){  
          23         obj1.rowSpan++;  
          24         obj2.parentNode.removeChild(obj2);  
          25         } else{                                       
          26       count[t]=n;//當第一個人的名稱合并結束時,給count[t]賦值做標記
          27 obj1=document.getElementById("tb__"+t.toString()+"_"+(num-1).toString());   }         
          28                          }        
          30                                    }
          31            //如果endcol未定義,代碼將最終一列定義為endcol   
          32           //  if(typeof(endcol)=='undefined'){end=colCount;}else{end=endcol}    
          33         for   (i=0;i<colCount;i++){ 
          34           //bool:合并方式,true代表兩邊合并;false代表中間合并
          35                if(bool){if (i+1<stacol||i+1>endcol){ continue;}}
          36                else{ if (i+1>stacol&&i+1<endcol){ continue;}  }
          37         obj1=document.getElementById("tb__0_"+i.toString());  
          38              for(j=1;j<rowCount;j++){  
          39   obj2=document.getElementById("tb__"+j.toString()+"_"+i.toString());   
          40              if(typeof(count[j])!='undefined'){
          41                        if(count[j]!=n){
          42              if(obj1.innerHtml==obj2.innerHtml){                           obj1.rowSpan++;  
          43                                obj2.parentNode.removeChild(obj2);  }
          44      else{  obj1=document.getElementById("tb__"+j.toString()+"_"+i.toString()); }      
          45 } else{  obj1=document.getElementById("tb__"+j.toString()+"_"+i.toString()); }  
          46 }   
          47   else{      if(obj1.innerHTML==obj2.innerHTML){  
          48              obj1.rowSpan++;  
          49              obj2.parentNode.removeChild(obj2);  
          50                      }
          51   else{  obj1=document.getElementById("tb__"+j.toString()+"_"+i.toString()); } 
          52                               
          53                                                         }  
          54                                                    }    
          55                             }

          posted on 2012-01-13 21:48 張翅傲仙 閱讀(1261) 評論(2)  編輯  收藏

          評論

          # 濟南上門按摩 http://jinan.anmotang.com 2012-01-14 11:44 按摩堂

          謝謝分享 占樓  回復  更多評論   

          # re: IE,谷歌,遨游,火狐兼容的萬能合并單元格方法 2012-01-15 16:36 allenny

          傲游和IE有區別嗎?  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          主站蜘蛛池模板: 台东市| 颍上县| 伽师县| 南通市| 桐梓县| 郎溪县| 丘北县| 岐山县| 乐业县| 巴楚县| 漠河县| 抚州市| 垦利县| 横峰县| 黄骅市| 皮山县| 保山市| 隆安县| 繁昌县| 航空| 德庆县| 保康县| 图们市| 三都| 全州县| 观塘区| 济宁市| 夹江县| 巴马| 凌海市| 常宁市| 堆龙德庆县| 济宁市| 自贡市| 松潘县| 巴南区| 兴安县| 噶尔县| 乃东县| 山东| 平罗县|