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>“表格标题”。它可以更容易地设置表格的样式。
添加回答
举报