生成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