当单击添加按钮时,我试图让一个添加按钮出现在每一行的下一行。目前我在我希望添加按钮出现的单元格中得到一个空文本字段。当单击添加按钮时,我必须更改我的代码才能获得添加按钮而不是文本字段?
对于添加按钮的 JavaScript,我目前拥有:
// button cell
var cellRightSel = row.insertCell(3);
var bt = document.createElement('input');
bt.name = 'addBt' + iteration;
bt.id = 'addBt' + iteration;
cellRightSel.appendChild(bt);
页面的 html 是:
<table border="1" id="tblSample">
<tr>
<th colspan="3">Sample table</th>
</tr>
<tr>
<td><input type="text" name="txtRow1"
id="txtRow1" size="40" /></td>
<td><input type="text" name="txtRow2"
id="txtRow3" size="40" /></td>
<td>
<select name="selRow0">
<option value="value0">text zero</option>
<option value="value1">text one</option>
</select>
</td>
<td><input type="button" value="Add" onclick="addRowToTable();" name="addBt0" /></td>
</tr>
</table>
最佳答案
bt.type = "button"
你忘了把它变成一个按钮。
或者你可以做
var bt = document.createElement('button');
制作<button>
反而。
关于Javascript将按钮添加到表中的下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6006358/