<!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(&quot;input&quot;);
checkbox.type = &quot;checkbox&quot;;
checkboxCell.appendChild(checkbox);</p>
<p>// 创建输入框单元格
var inputCell = row.insertCell(1);
var input = document.createElement(&quot;input&quot;);
input.type = &quot;text&quot;;
inputCell.appendChild(input);</p>
<p>// 创建按钮单元格
var buttonCell = row.insertCell(2);
var button = document.createElement(&quot;button&quot;);
button.innerHTML = &quot;按钮&quot;;
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 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录