1

まず、ユーザーに 1 つのファイル入力フィールドを表示しています。ユーザーは「1 つ追加」をクリックして 1 つの入力フィールドを追加できますが、既にファイルを選択してから「入力フィールドを追加」をクリックすると、以前のすべての入力フィールドで選択したファイルが表示されます。消える。これを修正する方法はありますか?

ここに私の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>
4

1 に答える 1

2

あなたはこれを試すことができます

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

デモ

于 2012-09-26T19:26:13.507 に答える