<script> </p> <p> ///////////////////////////////////////// ////// </p> <p> //Function: Merge tables </p> <p> //Parameters: tb-Table ID that needs to be merged </p> <p> //Parameter: colLength--The first few columns need to be merged, for example, </p> <p> // If you want to merge the first two columns, ignore the merging of the following data columns. colLength should be 2 </p> <p> //The default means merging all columns </p> <p> //data:2011.11.06 </p> <p> /////////// ///////////////////////////////////// </p> <p> function uniteTable(tb,colLength){ </p> <p> // Check whether the table is regular </p> <p> if(!checkTable(tb)) return; </p> <p> var i=0; </p> <p> var j=0; </p> <p> var rowCount=tb.rows.length; //number of rows </p> <p> var colCount= tb.rows[0].cells.length; //Number of columns </p> <p> var obj1=null; </p> <p> var obj2=null; </p> <p> //Name each cell </p> <p> for(i=0;i<rowCount ;i++){ </p><p> for(j=0;j<colCount;j++){ </p><p> tb.rows[i].cells[j].id="tb__" + i.toString() + "_" + j .toString(); </p><p> } </p><p> } </p><p> //Check the merge column by column </p><p> for(i=0;i<colCount;i++){ </p><p> if(i==colLength) return; </p> <p> obj1=document .getElementById("tb__0_"+i.toString()) </p><p> for(j=1;j<rowCount;j++){ </p><p> obj2=document.getElementById("tb__"+j.toString()+"_"+ i.toString()); </p><p> if(obj1.innerText==obj2.innerText){ </p><p> obj1.rowSpan++; </p><p> obj2.parentNode.removeChild(obj2); </p><p> , ("tb__"+j.toString()+"_"+i.toString()); </p><p> // ////////////////////////////// </p><p> //Function: Check whether the table is regular or not </p><p> //Parameter: tb--Need to check Form ID </p><p> //data: 2011.11.06 </p><p> //////////////////////////////////// ///// </p><p> function checkTable(tb){ </p><p> if(tb.rows.length==0) return false; </p><p> if(tb.rows[0].cells.length==0) return false; </p><p> for(var i=0;i<tb.rows.length;i++){ </p><p> if(tb.rows[0].cells.length!=tb.rows[i].cells.length) return false; </p><p> } </p><p> return true; </p><p> } </p><p> </script>
100 | ||||
a | for | 100 | 300 | 2 |
a | www.2cto.comif | 100 | 200 | 3 |
a | if | 300 | 230 | 4 |
a | if | 320 | 230 | 5 |
、