2012-07-27 1 views

답변

1

이것은 자바 스크립트로 수행 할 수 있습니다.

electrictoolbox.com에서 Clear upload file input field with jQuery 소식 인용 :

함수 reset_html (ID) {$ ('#'+ ID) .html 중에서 ($ ('#'+ ID) .html 중에서()); }

$ (문서) .ready (함수() {

var file_input_index = 0; 
$('input[type=file]').each(function() { 
    file_input_index++; 
    $(this).wrap('<div id="file_input_container_'+ 
        file_input_index+'"></div>'); 
    $(this).after('<input type="button" value="Clear" 
        onclick="reset_html(\'file_input_container_'+ 
             file_input_index+'\')" 
        />'); 
}); 

});

+0

실제로 솔루션을 주셔서 감사합니다. http://gusiev.com/2009/04/clear-upload-file-input-field/에 대한 참조와 함께 자바 스크립트를 사용했습니다. – Karan

0

유효성을 검사하지 않은 양식을 게시하려고하면 양식을 다시 렌더링 할 때 파일 필드가 비어있게됩니다.

나를 위해 Django Form File Field disappears on form error

다음 작품 .. 더 설명이 문제를 참조하십시오.

if 'submit-clear' in request.POST: 
    return HttpResponseRedirect('') 

이 어떤 filefields을 취소해야합니다 .. 당신의 HTML을 사용하여이 버튼을 처리보기에 그런

<input type="submit" name = "submit-clear" value="clear file"> 

에 명확한 버튼을 추가하지만이 경우 또한, 사용자가 만든 다른 설정을 제거합니다 다른 설정을 보존하고 파일 필드를 제거한 다음 양식이 어떻게 든 유효성을 검사하여 다시 렌더링되도록하십시오.

관련 문제