我想达到这种效果是图片最上面的表:
我的代码是这么写的:
<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>
它生成的是左下角的表。
请问哪位哥哥姐姐能给我说下它生成表的过程,怎么写才能生成我想要的表??谁先帮我解决分就给他/她了。速度了!!
我的代码是这么写的:
<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>
它生成的是左下角的表。
请问哪位哥哥姐姐能给我说下它生成表的过程,怎么写才能生成我想要的表??谁先帮我解决分就给他/她了。速度了!!
->
<td rowspan=2>...
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;
就可以了。
但我不知道这是为什么。