HTML表格动态添加行 - 添加复选框、输入框和按钮
<!DOCTYPE html>
<html>
<head>
<title>Add Row</title>
<script>
function addRow() {
// 获取表格
var table = document.getElementById("myTable");
<p>// 创建新行
var row = table.insertRow(-1);</p>
<p>// 创建复选框单元格
var checkboxCell = row.insertCell(0);
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkboxCell.appendChild(checkbox);</p>
<p>// 创建输入框单元格
var inputCell = row.insertCell(1);
var input = document.createElement("input");
input.type = "text";
inputCell.appendChild(input);</p>
<p>// 创建按钮单元格
var buttonCell = row.insertCell(2);
var button = document.createElement("button");
button.innerHTML = "按钮";
buttonCell.appendChild(button);
}
</script></p>
</head>
<body>
<table id="myTable">
<tr>
<th>复选框</th>
<th>输入框</th>
<th>按钮</th>
</tr>
</table>
<button onclick="addRow()">添加行</button>
</body>
</html>
当点击"添加行"按钮时,将在表格中添加一行,该行包含一个复选框、一个输入框和一个按钮。
原文地址: https://www.cveoy.top/t/topic/pL79 著作权归作者所有。请勿转载和采集!