请问js动态创建文本框,如何获取动态文本框的值呢?
<html><body><scriptlanguage="javascript"><!--varnewItemNumber=1;functionadditem(id){v...
<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=\"text\" name=\"sl" + newItemNumber + "\"><input type=\"button\" value=\"del\" onclick=\'deleteitem(this);\'>";
document.getElementsByName("totalNumber")[0].value = newItemNumber++;
}
}
function deleteitem(obj)
{
var curRow = obj.parentNode.parentNode;
tb.deleteRow(curRow.rowIndex);
document.getElementsByName("totalNumber")[0].value = eval(document.getElementsByName("totalNumber")[0].value) - 1;
}
//-->
</script>
<form name="form" method="post" action="test.asp?action=tj" >
<table id="tb"></table>
<input name="button" type=button onClick='additem("tb")' value="add>>">
<input type="hidden" name="totalNumber" value=""> <!-- 记录增加了多少文本框 //-->
<input type="submit" name="submit" value="submit">
</form>
<%
if request("action")="tj" then
a=request("totalNumber")
response.write(a)
end if
%>
<%
if request("action")="tj" then
Dim i,Total
Total=Request.Form("StuName").Count
Response.Write "all"&Total&"numbers"
For i=0 To Request.Form("StuName").Count
Response.Write "numbers"&i&Request.Form("StuName")(i)&"<br/>"
Next
End IF
%>
</body>
</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=\"text\" name=\"sl" + newItemNumber + "\"><input type=\"button\" value=\"del\" onclick=\'deleteitem(this);\'>";
document.getElementsByName("totalNumber")[0].value = newItemNumber++;
}
}
function deleteitem(obj)
{
var curRow = obj.parentNode.parentNode;
tb.deleteRow(curRow.rowIndex);
document.getElementsByName("totalNumber")[0].value = eval(document.getElementsByName("totalNumber")[0].value) - 1;
}
//-->
</script>
<form name="form" method="post" action="test.asp?action=tj" >
<table id="tb"></table>
<input name="button" type=button onClick='additem("tb")' value="add>>">
<input type="hidden" name="totalNumber" value=""> <!-- 记录增加了多少文本框 //-->
<input type="submit" name="submit" value="submit">
</form>
<%
if request("action")="tj" then
a=request("totalNumber")
response.write(a)
end if
%>
<%
if request("action")="tj" then
Dim i,Total
Total=Request.Form("StuName").Count
Response.Write "all"&Total&"numbers"
For i=0 To Request.Form("StuName").Count
Response.Write "numbers"&i&Request.Form("StuName")(i)&"<br/>"
Next
End IF
%>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询