求助一个问题:动态添加删除一个文件控件,添没什么,但删除遇到点问题
代码如下:大侠最好能给出改动后的程序
var fjNo=0;
function addFujian() {
var str = ' <span name=fj '+ fjNo+ '> <input type= "button " value= "删除 "onclick= "delFujian( '+fjNo + '); "> <INPUT type= "file " size= "40 " NAME= "File "> <br> </span> '
fjNo++;
document.getElementById( 'fjlist ').insertAdjacentHTML( "beforeEnd ",str)
document.getElementById( 'addB ').value = "继续添加 ";
}
function delFujian( no ){
var node = document.getElementByName( "fj "+no );
node.parentNode.removeChild( node );
}
<body>
<form method= "post " name= "mail " action= "tosend.jsp?submit=a " ENCTYPE= "multipart/form-data " >
<input type= "button " value= "添加附件 " onclick= "addFujian(); " id= "addB ">
</form>
<p id= "fjlist ">
</p>
</body>
------解决方案--------------------删除也用getElementById呀
getElementsByName you 个 s ,getElementsByName 取的是个数组,删要用getElementsByName(“”)[0]
------解决方案--------------------function delFujian( no ){
var node = document.getElementsByName( "fj "+no )[0];
node.parentNode.removeChild( node );
}