感谢您的支持,我会继续努力的!
打开微信扫一扫,即可进行扫码打赏哦
点我查看本站打赏源码!
Powered by RUNCODEX.COM,学的不仅是技术,更是梦想!!!
<table border="0" cellspacing="0" cellpadding="0">
<tbody id="tbody" border="1">
<tr >
<th>名字</th>
<th>性别</th>
<th>操作</th>
</tr>
<tr>
<td><input type="text" name="text1" /></td>
<td><input type="text" name="text2" /></td>
<td><input type="button" value="删除" onclick="removeRow(this.parentNode.parentNode)"></td>
</tbody>
</table>
<input name="button" type="button" value="添加行" onclick="addRow()">
xxxxxxxxxx
function addRow()
{
var root = document.getElementById("tbody")
var allRows = root.getElementsByTagName('tr');
var allCells = allRows[1].getElementsByTagName('td');
var newRow = root.insertRow();
var newCell0 = newRow.insertCell();
var newCell1 = newRow.insertCell();
var newCell2 = newRow.insertCell();
var newCell3 = newRow.insertCell();
newCell0.innerHTML = allCells[0].innerHTML;
newCell1.innerHTML = allCells[1].innerHTML;
newCell2.innerHTML = allCells[2].innerHTML;
newCell3.innerHTML = allCells[3].innerHTML;
}
function removeRow(r)
var root = r.parentNode;
var allRows = root.getElementsByTagName('tr')
if(allRows.length>2)
root.removeChild(r);
else
alert("only one row left, you not need to remove it.");
输入 CSS 代码……