如何使用JavaScript在另一个表中创建表?

如何使用JavaScript在另一个表中创建表?,javascript,html,dynamic,html-table,Javascript,Html,Dynamic,Html Table,我正在使用JavaScript动态创建一个表。我至少有一个我想要的例子。以下是要生成的HTML: 第1行第1单元 ... // create new table const newTable = document.createElement('table') // target cell, this is selecting every td inside your mainTable const target = document.querySelectorAll('#mainTable

我正在使用JavaScript动态创建一个表。我至少有一个我想要的例子。以下是要生成的HTML:

第1行第1单元 ...
// create new table
const newTable = document.createElement('table')

// target cell, this is selecting every td inside your mainTable
const target = document.querySelectorAll('#mainTable td')

// add new Table to first cell (if you want to add to specific cell you can add a class to it and the target it like that) or change the number in brackets:
target[0].appendChild(newTable)