// 创建一个 3 行 3 列的表格
const table = document.createElement("table");
table.setAttribute("border", "1");
table.setAttribute("cellspacing", "0");
// 创建表头
const thead = document.createElement("thead");
const trHead = document.createElement("tr");
const th1 = document.createElement("th");
th1.innerText = "列标题 1";
const th2 = document.createElement("th");
th2.innerText = "列标题 2";
const th3 = document.createElement("th");
th3.innerText = "列标题 3";
trHead.appendChild(th1);
trHead.appendChild(th2);
trHead.appendChild(th3);
thead.appendChild(trHead);
// 创建表体
const tbody = document.createElement("tbody");
for (let i = 1; i <p>以上代码会在页面中创建如下表格:</p>