转:http://download.csdn.net/download/h405055468/2853983
<html>
<body>
<script language="javascript">
<!--
var newItemNumber = 1;
function additem(id)
{
var row,cell,str;
row = document.getElementById(id).insertRow();
if(row != null )
{
cell = row.insertCell();
cell.innerHTML="<input type=\"text\" name=\"StuName" + newItemNumber + "\"><input type=\"button\" value=\"删除\" onclick=\'deleteitem(this);\'>";
document.getElementsByName("totalNumber")[0].value = newItemNumber++;
}
}
function deleteitem(obj)
{
var curRow = obj.parentNode.parentNode;
alert(curRow);
tb.deleteRow(curRow.rowIndex);
document.getElementsByName("totalNumber")[0].value = eval(document.getElementsByName("totalNumber")[0].value) - 1;
}
//-->
</script>
<form name="form" method="post" action="addrow.php">
<table id="tb"></table>
<input type="text" name="num">
<input name="button" type=button onClick='additem("tb")' value="添加>>">
<input type="text" name="totalNumber" value=""> <!-- 记录增加了多少文本框 //-->
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>