运行正常
<form name="form" method="post" ACTION="/jspsmartupload/jsp/uploaddb.jsp" enctype="multipart/form-data" target="editpost" ID="Form1">
  <select class="TBGen" name="SelectFile" style="width:400" size="4">
  </select>
  <button onclick="DelFiletoSelect()">删除附件</button>
<br>
<br>
<table>
<tr>
<td>
<span id="AffixFile">
 <span><input  name="affixs" type="file" size=50></span>
</span>
<input type="button" name="insert" value="插入附件" onClick="AddFiletoSelect(document.form.affixs);affixs.select();execCommand('delete')">
</td>
</tr>
</table>  <p>
    <input type="submit" name="Submit" value="提交">
  </p>
</form>
<SCRIPT LANGUAGE="JavaScript">
 function AddFiletoSelect(aoFile){
   if ((aoFile==null)||(aoFile.value=="")) return;
   var loOpts = form.SelectFile.options;
   loOpts[loOpts.length] = new Option(aoFile.value,aoFile.uniqueID);
   
   //var loObj = document.createElement("span");
   //loObj.innerHTML = '<input  name="affixs" type="file" >';
 
   //AffixFile.insertBefore(loObj);
 }
 function DelFiletoSelect(){
  loEL = document.all(form.SelectFile.value);
  //if (loEL!=null){
  // loEL = loEL.parentElement;
  // AffixFile.removeChild(loEL);
// }
  var loOpts = form.SelectFile.options;
  if(loOpts!=null&&loOpts.length>0){
   loSel = loOpts[form.SelectFile.selectedIndex]
   loOpts.removeChild(loSel);
  }
 }
</SCRIPT>

解决方案 »

  1.   

    seabell(百合心) :这样我这边也测试成功了,但是只是 页面上能通过,不能调用上传.
    不能把
    var loObj = document.createElement("span");
     loObj.innerHTML = '<input  name="affixs" type="file" >';
     AffixFile.insertBefore(loObj);
    屏蔽掉的,因为我在调用jsp上传的时候找的是type="file",所以必须要在添加完列表以后动态增加文件.
      

  2.   

    下面是我现在的代码,在添加第二个文件的时候出现问题
    <form name="form" method="post" ACTION="/jspsmartupload/jsp/uploaddb.jsp" enctype="multipart/form-data" target="editpost" ID="Form1">
      <select class="TBGen" name="SelectFile" style="width:200" size="4">
      </select>
      <button onclick="DelFiletoSelect()">删除附件</button>
    <br>
    <br>
    <table>
    <tr>
    <td>
    <span id="AffixFile">
     <span><input  style="width:250" name="affixs" type="file" ></span>
    </span>
    <input type="button" name="insert" value="插入附件" onClick="AddFiletoSelect(document.form.affixs)">
    </td>
    </tr>
    </table>  <p>
        <input type="submit" name="Submit" value="提交">
      </p>
    </form>
    <SCRIPT LANGUAGE="JavaScript">
     function AddFiletoSelect(aoFile){
       if ((aoFile==null)||(aoFile.value=="")) return;
       var loOpts = form.SelectFile.options;
       loOpts[loOpts.length] = new Option(aoFile.value,aoFile.uniqueID);
       aoFile.parentElement.style.display = "none";
       var loObj = document.createElement("span");
       loObj.innerHTML = '<input  style="width:400" name="affixs" type="file" >';
     
       AffixFile.insertBefore(loObj);
     }
     function DelFiletoSelect(){
      loEL = document.all(form.SelectFile.value);
      if (loEL!=null){
      loEL = loEL.parentElement;
      AffixFile.removeChild(loEL);
     }
      var loOpts = form.SelectFile.options;
      if(loOpts!=null&&loOpts.length>0){
       loSel = loOpts[form.SelectFile.selectedIndex]
       loOpts.removeChild(loSel);
      }
     }
    </SCRIPT>
      

  3.   

    <SCRIPT LANGUAGE="JavaScript">
    i=0;
     function AddFiletoSelect(aoFile){
    alert(aoFile);
       if ((aoFile==null)||(aoFile.value=="")) return;
       var loOpts = form.SelectFile.options;
       loOpts[loOpts.length] = new Option(aoFile.value,aoFile.uniqueID);
       aoFile.style.display = "none";
       var loObj = document.createElement("span");
       loObj.innerHTML = '<input  style="width:400" name="affixs'+(++i)+'" type="file">';
       AffixFile.insertBefore(loObj);
     }
     function DelFiletoSelect(){
      loEL = document.all(form.SelectFile.value);
      if (loEL!=null){
      loEL = loEL.parentElement;
      AffixFile.removeChild(loEL);
     }
      var loOpts = form.SelectFile.options;
      if(loOpts!=null&&loOpts.length>0){
       loSel = loOpts[form.SelectFile.selectedIndex]
       loOpts.removeChild(loSel);
      }
     }
    </SCRIPT><form name="form" method="post" ACTION="/jspsmartupload/jsp/uploaddb.jsp" enctype="multipart/form-data" target="editpost" ID="Form1">
      <select class="TBGen" name="SelectFile" style="width:200" size="4">
      </select>
      <button onclick="DelFiletoSelect()">删除附件</button>
    <br>
    <br>
    <table>
    <tr>
    <td>
    <span id="AffixFile">
     <span><input  style="width:250" name="affixs0" type="file" ></span>
    </span>
    <input type="button" name="insert" value="插入附件" onClick="AddFiletoSelect(eval('document.form.affixs'+i))">
    </td>
    </tr>
    </table>  <p>
        <input type="submit" name="Submit" value="提交">
      </p>
    </form>