防止使用Javascript(JQuery)更改文件输入 [英] Prevent file input from changing with Javascript (JQuery)
本文介绍了防止使用Javascript(JQuery)更改文件输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有条件地告诉用户文件太大,我试图防止文件输入被更改,但是即使捕获更改并防止默认设置,它仍然会被填充,即:
I'm trying to prevent a file input being changed if I conditionally tell the user the file is too large, but even capturing the change and preventing default, it's still filled in ie:
// CHECK FILE ISNT ABOVE 500MB ON CHANGE
$(".upload-file").change(function (e) {
// conditional checks
var fileSize = $('.upload-file').get(0).files[0].size; // in bytes
if (fileSize > 500000000) {
e.preventDefault();
swal('File size is more than 500 MB, please upload a smaller file. Support for larger files will be rolled out soon.');
return false;
}
});
这是我的代码,我在做什么错?
Here's my code, what am I doing wrong?
推荐答案
如果要重置文件输入:
$(".upload-file").val(null);
这篇关于防止使用Javascript(JQuery)更改文件输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文