这段代码的问题是,当我们要添加一行时,它只会在一列中添加一行。请问有人可以告诉我如何拆分列吗?
JavaScript:
function Myfunction(tableid) {
var table=document.getElementById("tablerow");
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(0);
cell2.innerHTML = rowCount + 1;
var cell3 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text";
cell3.appendChild(element2);
}
HTML:
<body>
<table id="tablerow" border="1" align="center">
<tr>
<td><center>1</center></td>
<td><input type="textbox" name="" value=""></td>
<td><input type="textbox" name="" value=""></td>
<td><input type="textbox" name="" value=""></td>
</tr>
<tr>
<td><center>2</center></td>
<td><input type="textbox" name="" value=""></td>
<td><input type="textbox" name="" value=""></td>
<td><input type="textbox" name="" value=""></td>
</tr>
<center><input type="button" value="Add Row" onclick="Myfunction()">