如何实现一下功能:
点击“增加附件”按钮,增加一个file控件和一个“删除附件”按钮。
点击“删除附件”按钮,删除刚才增加的file控件和“删除附件”按钮。

解决方案 »

  1.   

    <html>
    <head>
    </head>
    <body>
    <div id='div1' style='visibility: hidden'>
      <input type='file' name='txtfn'/>
    </div><input type='button' value='show' onclick='f();'/><script language=jscript>
      function f() {
        document.all.div1.style.visibility = 'visible';
      }
    </script>
    </body>
    </html>将 visibility 再设置为 'hidden' 就又看不见了。
      

  2.   

    上面的例子 只能增加一个file控件!
    而且file控件div为'hidden' 时,它还占据着一个控件的位置我希望能增加多个控件,而且点击“删除”按钮时,file控件消失的同时,下面的元素能上移,而不至于留下一块空白的区域可参见163邮箱增加附件的效果还有没有好办法??非常感谢!
      

  3.   

    可以再附件处加一个iframe,点击增加附件时候刷新iframe,把iframe调用的jsp页面改了
      

  4.   

    visibility 再设置为 'hidden'
      

  5.   

    function spread()
    {
        document.getElementById("ok").style.display= (document.getElementById("ok").style.display =='none')?'':'none';
    }
    <table id="ok" style="display:none">
    <tr  align="center" bgcolor="#FFFFFF" >
    <td colspan="7">
     <input type='file' name='txtfn'/>
    </td>
    </tr>
    </table>
    <input type='button' value='show' onclick='spread();'/>
      

  6.   

    <html>
    <head>
    <title>Test</title>
    <script type="text/javascript">
    <!--
    var sequence = 0;
    function addAttachment() {
      var index = sequence++;
      var area = document.getElementById("attach_area");
      area.innerHTML += 
      "<div id=\"attach_" + index + "\">" +
      "<input id=\"attach_file\" type=\"file\" />" + //所有的上传文件作成一个控件数组没问题吧
      "<input type=\"button\" value=\"删除\" onclick=\"removeAttachment(" + index + ")\">" +
      "</div>";
    }function removeAttachment(index) {
      var attachment = document.getElementById("attach_" + index);
      if (attachment == null) {
        return;
      }
      attachment.innerHTML = "";
      attachment.outerHTML = "";
    }function removeAll() {
      if (sequence != 0 && !confirm("您确定吗?")) {
        return;
      }
      for (var i = sequence; i-- > 0; removeAttachment(i));
      sequence = 0;
    }
    //-->
    </script>
    </head>
    <body>
    <form action="">
    <div id="attach_area">
    </div>
    <input type="button" value="追加" onclick="addAttachment()"/>
    <input type="button" value="全删除" onclick="removeAll()"/>
    </form>
    </body>
    </html>