javascript动态创建文本框带删除

转: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>

    A+
发布日期:2014年09月19日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: