2012-02-07 50 views
1

我在html中看到了文件輸入的缺陷。當用戶使用文件輸入來選擇文件時,那很好,但是如果用戶想要刪除選定的文件並且想要空白文件輸入,那麼用戶不能這樣做。有誰知道如何從文件輸入中刪除選定的文件?如何從輸入文件中刪除選定的文件?

下面是我的jQuery文件輸入代碼:

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

重複。看到這裏的答案:http://stackoverflow.com/a/1043969/507784 – GregL 2012-02-07 01:40:22

+1

投票關閉作爲[清除使用jQuery](http://stackoverflow.com/問題/ 1043957 /清除輸入類型文件使用jquery) – jfriend00 2012-02-07 01:52:26

回答

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/ – 2013-11-04 07:28:53

相關問題