2012-09-26 3 views
1

과 함께 하나 더 추가하면 사라집니다. 사용자에게 하나의 파일 입력 필드가 표시되고 하나의 입력 필드를 추가하기 위해 "추가"를 클릭 할 수 있습니다. 그러나 이미 파일을 선택한 경우 나중에 "입력 필드 추가"를 클릭하면 이전 입력 필드에 대해 선택한 파일이 사라집니다. 해결 방법이 있습니까? 당신이파일 업로드 필드 입력이 자바 스크립트 함수

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

DEMO을 시도 할 수

<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> 

답변

2

:

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

여기 내 HTML 양식입니다 :

여기 내 자바 스크립트 함수입니다.

+0

정확히 내가 필요한 것, 정말 고마워요! – Graviton

+0

당신은 환영합니다 :-) –