2012-02-07 95 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

相关问题