2012-02-07 25 views
1

私はhtmlでファイル入力の欠陥を見ました。ユーザーがファイル入力を使用してファイルを選択すると、それは問題ありませんが、ユーザーが選択したファイルを削除して空のファイル入力をしたい場合、ユーザーはこれを行うことはできません。誰もファイル入力から選択したファイルを削除する方法を知っていますか?以下は入力ファイルから選択したファイルを削除するにはどうすればよいですか?

はjqueryの中に私のファイル入力コードです:

var $imagefile = $('<input />') 
    .attr({ 
     type: 'file', 
     name: 'imageFile', 
     id: 'imageFile' 
    }); 
+1

重複。回答についてはこちらを参照してください:http://stackoverflow.com/a/1043969/507784 – GregL

+1

jQueryを使用して[を消去する]の複製としてクローズする投票(http://stackoverflow.com/質問/ 1043957 /クリア入力型ファイル使用のjquery) – jfriend00

答えて

1

グレート、それが動作する...

function reset_html(id) 
{ 
    $('#'+id).html($('#'+id).html()); 
} 

$(document).ready(function() 
{ 
    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://www.electrictoolbox.com/clear-upload-file-input-field-jquery/ –

関連する問題