我有一个文件输入:
<img id="uploadPreview">
<div id="changeImage">Change</div>
<div id="customImage">
<input type="file" id="myfile" multiple style="display:none" onchange="PreviewImage();" />
<div class='upload blank' id="add-image"></div>
</div>
函数如下:
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("myfile").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("myfile").files[0]);
$("#uploadPreview").removeClass('hide'); //for manipulating something in the dom
$('#changeImage').removeClass('hide'); //for manipulating something in the dom
$("#customImage").addClass('hide'); //these are for manipulating something in the dom
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
一切正常。现在我有一个更改按钮。我希望如果有人点击它,那么之前上传的文件详细信息就会消失。函数如下所示:
$('#changeImage').click(function(){
$('#uploadPreview').addClass('hide');
$('#customImage').removeClass('hide');
//here I want to remove/clear the details about the already previous uploaded file in the 'file-input'. So the same image can be shown if someone clicks it for once again.
});
你能帮忙吗?
最佳答案
如果你想在其他表单域中保留数据,你可以使用
HTML
<input type='file' id='yourid' />
jQuery
$('#yourid').val('');
这将从输入标签中清除您上传的文件
关于javascript - 如何从 HTML5 FileReader 中的 'input type' 清除以前的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251875/