1 回答

TA貢獻1828條經驗 獲得超4個贊
你需要改變兩件事:
添加一個 } 關閉函數
將row += "<tr>";(未聲明的變量)更改為table += "<tr>";
gangetabellen()
<div id="tabell"></div>
<script>
function gangetabellen() {
var tall1, tall2, produkt;
var tabell = "<table style='width:500px'>";
// If you want a header you should add a for-loop here to add
// a row with tall2
for (tall1 = 10; tall1 <= 19; tall1++) {
tabell += "<tr>";
// If you want a header to the left you should add it here.
for (tall2 = 1; tall2 <= 19; tall2++) {
produkt = tall1 * tall2;
tabell += "<td>" + produkt + "</td>";
}
tabell += "</tr>";
}
tabell += "</table>";
document.getElementById("tabell").innerHTML = tabell;
}
</script>
如果你想在邊緣顯示tall1,tall2你需要為此添加代碼(并且你可以使用<th>而不是<td>“表格標題”。它可以更容易地設置表格的樣式。
添加回答
舉報