我想达到这种效果是图片最上面的表: 
我的代码是这么写的: 
<html> 
<table id="tab" border="1" width=50% height=50%> 
<script language="javascript"> 
for(i=0;i<3;i++) 

document.write("<tr>"); 
for(j=0;j<3;j++) 
{ if(i==0 &&j==0) 

document.write("<td>colspan=2</td>"); 
tab.rows[0].cells[0].rowSpan=1; 
tab.rows[0].cells[0].colSpan=2; 

else if(i==0&&j==2) 

document.write("<td>rowspan=2</td>"); tab.rows[0].cells[1].rowSpan=2; 
tab.rows[0].cells[1].colSpan=1; 

else if((i==0&& j==1)||(i==1&&j==2)) 
continue; 
else 

document.write("<td>1</td>"); 


document.write("</tr>"); 

</script> 
</table> 
</html> 
它生成的是右下角的那张表。 
我的代码这么写: 
<html> 
<table id="tab" border="1" width=50% height=50%> 
<script language="javascript"> 
for(i=0;i<3;i++) 

document.write("<tr>"); 
for(j=0;j<3;j++) 
{ if(i==0 &&j==0) 

document.write("<td>colspan=2</td>"); 
tab.rows[0].cells[0].rowSpan=1; 
tab.rows[0].cells[0].colSpan=2; 

else if(i==0&&j==2) 

document.write("<td>rowspan=2</td>"); 
tab.rows[0].cells[1].colSpan=1; 
tab.rows[0].cells[1].rowSpan=2; 

else if((i==0&& j==1)||(i==1&&j==2)) 
continue; 
else 

document.write("<td>1</td>"); 


document.write("</tr>"); 

</script> 
</table> 
</html> 
它生成的是左下角的表。 
请问哪位哥哥姐姐能给我说下它生成表的过程,怎么写才能生成我想要的表??谁先帮我解决分就给他/她了。速度了!!

解决方案 »

  1.   

    <td>rowspan=2...
    ->
    <td rowspan=2>...
      

  2.   

    你说的方法对,我想过,但我是从数据库里提的数据,<td>的多少每次是不定的,哪个<td>要rowspan,哪个要colspan,哪个既要rowspan又要colsapn是不定的。我偶然间得到了正确的方法。就是当行相同时先处理列数大的就可以了。
    eg:先
    tab.rows[0].cells[1].colSpan=1; 
    tab.rows[0].cells[1].rowSpan=2; 

    tab.rows[0].cells[0].colSpan=2; 
    tab.rows[0].cells[0].rowSpan=1; 
    就可以了。
    但我不知道这是为什么。