注册 登录
编程论坛 ASP技术论坛

请教一个自由添加 ’文本框‘ 的代码

kira007 发布于 2008-02-03 13:35, 885 次点击
如题
在ASP页面中,当点击表单中 某文本框(IMG) 旁边的 添加按钮,就会在 该文本框下面 复制出一个 IMG 文本框的功能如何实现的?
效果如下图

[[it] 本帖最后由 kira007 于 2008-2-3 13:47 编辑 [/it]]
2 回复
#2
madpbpl2008-02-03 22:25
有个类似的例子,楼主可以做个参考
<script language="vbscript">
function addfile()
dim str
str="<table>"
if not IsNumeric (window.form1.filenum.value) then window.form1.filenum.value =1
for i=1 to window.form1.filenum.value
str=str&"<tr><td valign='middle'>文件"&i&":</td><td><input type='file' name='file"&i&"' class='tx1' value size='20'></td></tr>"
next
window.uptd.innerHTML =str&"</table>"
end function
</script>
<form name="form1" method="post" action="">
<input name="filenum" class="tx2" value="1" size="4">
              个文件
              <div id="uptd"> </div></td>  
              <input type="button" name="Button" class="bt" onClick="addfile" value="设 定">
</form>
#3
yms1232008-02-04 15:28
<html>
<head>
<title>动态增加文本框</title>
<script language="javascript" >
var count=0;
function addText()
{
   count+=1;
   var newText=document.createElement("input");
   var br=document.createElement("br");
   newText.setAttribute("type","text");
   newText.setAttribute("name","txt"+count);
   newText.setAttribute("value","第"+count+"个文本框");
   document.body.appendChild(newText);
   document.body.appendChild(br);
}
</script>
</head>
<body>
<input type="button" name="addText" onClick="addText();" value="增加一个文本框"><br>
</body>
</html>
javascript的动态增加文本框,其实除了用HTML代码外,还可以使用DOM方法来增加文本框。
1