1,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"><br>
2,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"><br>
3,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"><br>
<input type=button value=delete onclick="d()" UNSELECTABLE=true>
<script>
var n = 0
function f(u)
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file") o[i].setAttribute("ok","")
u.setAttribute("ok","ok")
}
function d()
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file" && o[i].getAttribute("ok")=="ok") o[i].parentNode.removeChild(o[i])
}
</script>
2,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"><br>
3,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"><br>
<input type=button value=delete onclick="d()" UNSELECTABLE=true>
<script>
var n = 0
function f(u)
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file") o[i].setAttribute("ok","")
u.setAttribute("ok","ok")
}
function d()
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file" && o[i].getAttribute("ok")=="ok") o[i].parentNode.removeChild(o[i])
}
</script>
2,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"><br>
3,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"><br>
<input type=button value=delete onclick="d()" UNSELECTABLE=true>
<script>
var n = 0
function f(u)
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file") o[i].setAttribute("ok","")
u.setAttribute("ok","ok")
}
function d()
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file" && o[i].getAttribute("ok")=="ok") o[i].parentNode.removeChild(o[i])
}
</script>
但是如何清除删除控件留下的空白呢?
我想把控件间排紧凑点。
<div>1,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"></div>
<div>2,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"></div>
<div>3,<INPUT type="file" size="50" NAME="File" onfocus="f(this)"></div>
<input type=button value=delete onclick="d()" >
<script>
var n = 0
function f(u)
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file") o[i].setAttribute("ok","")
u.setAttribute("ok","ok")
}
function d()
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file" && o[i].getAttribute("ok")=="ok") o[i].parentNode.parentNode.removeChild(o[i].parentNode)
}
</script>
而且格式也比较好掌握
我用以下函数增加fiel控件,按你的方法加了<div>就有错误了。function addFile()
{
var str = '<div>
<INPUT type="file" size="50" NAME="File" onfocus="f(this)" br></div>'
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
}
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<TABLE>
<TR>
<TD id="MyFile"><div><INPUT type="file" size="50" NAME="File" onfocus="f(this)"></div>
<div><INPUT type="file" size="50" NAME="File" onfocus="f(this)"></div>
<div><INPUT type="file" size="50" NAME="File" onfocus="f(this)"></div></TD>
</TR>
</TABLE><input type=button value=delete onclick="d()" >
<script>
var n = 0
function f(u)
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file") o[i].setAttribute("ok","")
u.setAttribute("ok","ok")
}
function d()
{
o=document.getElementsByTagName("INPUT")
for(i=0;i<o.length;i++)
if(o[i].type=="file" && o[i].getAttribute("ok")=="ok") o[i].parentNode.parentNode.removeChild(o[i].parentNode)
}
function addFile()
{
var str = '<div> <INPUT type="file" size="50" NAME="File" onfocus="f(this)" br></div>'
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
}
</script>
<INPUT TYPE="button" value ="添加" onclick="addFile()">
</BODY>
</HTML>
没错呀!