生成HTML表格请帮忙下面提到scenario->使用循环
我有一个表这样的方式,从1到30想显示值是1,2,3号应该来一个标签和像其他tr标签中的明智4,5,6等直到30值。我想用table来显示表格中的值。其中每个值如“1”应该显示在一个中,不应该在不同的<TD>
等中显示“2”。
我的意思是说,值“1”应在<Table>
标签的单<TD>
显示,值“2”应该被显示在另一<td>
标签等,一个<Tr>
应当使用三个后续<TD>
S还之后。输出应为folllows - >
1 2 3
4 5 6
7 8 9
等等!
早期的反应将不胜感激。谢谢。
我已经试过代码如下给出
<script type="text/javascript">
document.write(" <table width='673' align='center' cellpadding='2' cellspacing='1'>");
document.write(" <tr>");
document.write(" <td valign = 'top'>");
document.write(" </td>");
document.write(" </tr>");
var cnt = 0;
for (var idx = 1; idx <= 30; idx++)
{
cnt = cnt + 1;
document.write(" <tr>");
document.write(" <td valign = 'top'>");
document.write(" <table width='100px' align='center' cellpadding='2' cellspacing='1'>");
document.write(" <tr>");
document.write(" <td align='center'>");
document.write(" " + idx + "");
document.write(" </td>");
document.write(" </tr>");
document.write(" <tr>");
document.write(" <td class='label'>");
document.write(" <span> name part : " + idx + "</span>");
document.write(" </td>");
document.write(" </tr>");
document.write(" </table>");
document.write(" </td>");
if (cnt = 3)
{
document.write(" </tr>");
}
if (cnt = 3) {
cnt = 0;
}
}
document.write(" </table>");
</script>
你刚才不是张贴同样的问题在http://stackoverflow.com/questions/ 9751799/generate-dynamic-html-using-for-loop? – j08691 2012-03-17 17:10:32
雅@ j08691但这次,我已经澄清了我的问题以及问题的详细解释!由于我的早期查询没有得到答复而关闭,因此我发布了新的Q. – hero123 2012-03-17 17:11:34
我很困惑。至少格式化你的问题的编码部分。 – Kaf 2012-03-17 17:15:13