日期:2014-05-16  浏览次数:20359 次

超链接添加 文件域(附件)
我想要实现的功能是:
有一个超链接标签   显示“添加附件”和一个文件域
然后点击“添加附件”网页会在原先的文件域下面多一的文件域,
点一次会多一个,点一次会多一个,
在每个多出来的文件域(第一个除外)后面有一个超链接标签显示“删除”,点击“删除”会把会把对应的文件域删除
就像163的写邮件的那个添加附件的功能~~~~我不知道那是隐藏还是删除

请各位指点指点~~~越全越好~~~有可能的话最好每个文件域的name不一样
谢谢~~~~~~~
<p> <a   href= "# "   > 添加附件 </a> </p>
<p>
    <input   name= "Input "   type= "file "   />
</p>
<p>
    <input   name= "Input2 "   type= "file "   />
    <a   href= "# "   > 删除 </a> </p>

------解决方案--------------------
看看这个方法:document.createElement
------解决方案--------------------
看看这个,你就会了
<html>
<title> </title>
<script language=javascript>
function aa()
{
for(i=0;i <form1.int1.value;i++)
{
intext = document.createElement( " <input name= 'text "+i+ " '> ");
document.form1.appendChild(intext);
}
}

</script>
<body>
<form name= "form1 " ID= "Form1 ">
<input type= "text " name= "int1 " ID= "Text1 ">
<input type= "button " name= "b1 " value= "生成 " onclick= "aa(); " ID= "Button1 ">
</form>
</body>
</html>

------解决方案--------------------
<html>
<title> </title>
<script language=javascript>
function aa()
{
intext= " ";
for(i=0;i <form1.int1.value;i++)
{
intext = intext+ " <input type=file name= 'text "+i
+ " '> <input type=button value=del onclick=del(this, "+i+ ")> ";

}
document.all.d1.innerHTML=intext
}

function del(obj,AIndex)
{

var oChild=d1.children( 'text '+AIndex);
if (oChild != null)
{
oChild.style.display= "none ";
obj.style.display= "none ";
d1.removeChild(oChild);
d1.removeChild(obj);
}

}

</script>
<body>
<form name= "form1 " ID= "Form1 ">
<input type= "text " name= "int1 " ID= "Text1 " value=2>
<input type= "button " name= "b1 " value= "生成 " onclick= "aa(); " ID= "Button1 ">
<div id=d1> </div>
</form>
</body>
</html>

------解决方案--------------------
采用隐藏:
oChild.style.display= "none ";
obj.style.display= "none ";
或采用删除:
d1.removeChild(oChild);
d1.removeChild(obj);