在代码中增加一个按钮,点击按钮后会弹出提示框,用户可以在提示框中输入内容,并将输入的内容添加到一个JSON对象数组的表格中。
HTML代码:
内容 |
---|
JavaScript代码:
let contentArray = [];
function addContent() { let content = prompt("请输入内容:"); let contentObject = {"content": content}; contentArray.push(contentObject);
let tableBody = document.getElementById("contentTable").getElementsByTagName("tbody")[0]; let newRow = tableBody.insertRow(); let newCell = newRow.insertCell(); let text = document.createTextNode(content); newCell.appendChild(text); }