javascript - HTML Input tag, with type file, in some cases doesn't catch "oninput " event
问题描述
So, in my file upload page, I have a file dragging and dropping area. By clicking on this area, the file input dialog appears to allow the user to select files. In some random cases after selecting the files and clicked Open, the oninput event is not emitted. Am I doing something wrong?
I tried to change the oninput event to onchange. And it's not working to. Has anyone had this problem? Thanks in advance.
let input = document.createElement("input");
input.type = "file";
input.style.cssText = "display:none;";
input.multiple = true;
input.accept = "." + this.options.allowedFileType;
input.oninput = () => {
Array.from(input.files).forEach(file => {
if (file.type === "application/pdf") {
self.setUniqueUuidAndStoreFile(file);
} else {
self.displayErrorNotification(
this.$t("file") + " " + file.name + " " + this.$t("wrongFileType")
);
}
});
};
input.ondrop = function (event) {
return false;
};
input.click();
解决方案
这是“正常”系统不时注册更改,因为出于安全原因,它看不到整个文件。我们使用的解决方法是将点击时的值设置为 null
input.onclick = function () {
this.value = null;
};
推荐阅读
- php - Laravel 5.4 类型错误:函数参数太少。0 已通过,恰好 1 预期在
- ionic-framework - 离子如何像另一个平台一样设置 Sass 变量
- java - 主程序中的扫描程序 Java 线程
- three.js - 三.js 图像纵横比
- java - 构建失败时,maven-surefire-report-plugin 不生成report.html
- php - 如何将两个不同函数的参数值获取到不同函数中的另一个变量中?
- mysql - 在模式弹出窗口中获取值并更新,而无需在 codeigntier 中刷新页面
- python - Python/Redis 中的任务委托
- c++ - Qt 应用程序有意外的 QDir::currentPath
- java - Springboot:组件类中的java.lang.NullPointerException @autowired