【问题标题】:file upload field input disappears upon adding another one with javascript function使用javascript函数添加另一个文件上传字段输入消失
【发布时间】:2012-09-27 03:26:13
【问题描述】:

首先,我向用户显示了一个文件输入字段,他们可以单击“添加一个”以添加一个输入字段,但是当他们已经选择了一个文件然后单击“添加输入字段”为所有选择的文件以前的输入字段消失。 有没有办法纠正这个问题?

这是我的 javascript 函数:

  function _add_more() {
    var txt = "<br><input type=\"file\" name=\"item_file[]\">";
    document.getElementById("files").innerHTML += txt;
  }

这是我的 html 表单:

<div id="form">

<h4>BOWMAN - Add an album <a href="index.php"> back</a></h4>
<form method="post" action="procesblogpost.php" enctype="multipart/form-data">
  <label for="title">Give the album it's name</label><br/>
  <input type="text" id="title" name="title" /><br/><br/>

  <label for="info">some info about the album?</label><br/>
  <textarea id="info" name="info"></textarea><br/><br/>
  <div id="uploadpic">
      <label for="picturelink">now choose some pictures</label><br/>
      <div id="files">
          <input type="file" name="item_file[]">
      </div>
      <a href="javascript:_add_more();" title="Add more">+</a>
  </div>
  <br/><br/>
  <input type="submit" id="submit" name="submit" value="send it of to the www" />
</form>

</div>

【问题讨论】:

    标签: php javascript file-upload


    【解决方案1】:

    你可以试试这个

    function _add_more() {
        var txt = document.createElement('input');
        txt.type="file";
        txt.name="item_file[]";
        document.getElementById("files").appendChild(txt);
    }
    

    DEMO.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      相关资源
      最近更新 更多