我可以知道如何將項目插入到我的表體中?我的代碼似乎不工作。將行添加到現有表
var tableRef = document.getElementById("myList").getElementsByTagName("tbody");
var newRow = tableRef.insertRow(tableRef.rows.length);
var newCell = tableRef.insertCell(0);
var myTextTwo = "hello world";
var newText = document.createTextNode(myTextTwo);
newCell.appendChild(newText);
<table id="myList">
<thead>
<tr>
<td>Product ID</td>
<td>Product Name</td>
<td>Quantity</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
你檢查你的JavaScript控制檯中的錯誤? – Blazemonger
@所以你已經從'.getElementsByTagName()'中省略了'[0]',並且你也嘗試添加新的單元到tbody中,而不是你必須添加的新行。看看我的答案更詳細的解釋:http://stackoverflow.com/a/38248819/6313073 –