Jquery 在 Internet Explorer 中重置文件上传

Jquery File Upload Reset in Internet Explorer

我在经典 asp 网络表单中使用 jquery。表单本身是基本的,最多只能上传 5 个文件。

上传文件时,我为用户提供了一个选项,可以删除正在上传的其中一个文件。我为此使用的 jquery 代码是

$('#delete_attachment').click(function() {
    if (confirm('Are you sure you want to delete this file?')) {
    $('#file_format').val('');//this is for a textbox and works fine
    $('#document_attachment').val('');//this is the line that deletes the file
    $('#document_comment').val('');//this is for a textbox and works fine too
    }
    });
});

这在 Chrome 中工作得很好并且文件已被删除。但是在 Internet Explorer 中,文件会保留并上传。有没有其他方法可以避免上传文件并使用常规 html 文件上传控制

将其从上传队列中删除

您不能更改文件输入类型的值,因为那样会引入安全漏洞。

而不是 $('#document_attachment').val(''); 你可以简单地做:

$('#document_attachment').replaceWith('<input name="file" type="file" id="document_attachment"/>');