[英]Create a html table where inputs are inside <td>
I have the following html table:我有以下 html 表:
<table> <tr> <td> <input> </td> <td> <input> </td> <td> <input> </td> </tr> <tr> <td> <input> </td> <td> <input> </td> <td> <input> </td> </tr> <tr> <td> <input> </td> <td> <input> </td> <td> <input> </td> </tr> </table>
Instead, I would like to create this table only with javascript .相反,我只想用 javascript创建这个表。 I have read the following post .我已阅读以下帖子。 However, I would like that inside every <td>
there is an <input>
(as shown on the code provided).但是,我希望在每个<td>
中都有一个<input>
(如提供的代码所示)。 Any guidance or help would be appreciated.任何指导或帮助将不胜感激。
Thanks!谢谢!
I found the answer:我找到了答案:
const table = document.querySelector('table'); function generateTable() { for (let i = 0; i < 5; i++) { const row = table.insertRow(); for (let a = 0; a < 5; a++) { const cell = row.insertCell(); const inputCell = document.createElement("INPUT"); cell.appendChild(inputCell); } } } generateTable()
<table> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.