客户端使用 HTML5 检查文件大小
htmlweb developmentfront end technology更新于 2025/8/18 14:04:17
在 HTML5 之前,文件大小是通过 Flash 检查的,但现在 Web 应用中已不再使用 Flash。客户端仍然可以通过在事件监听器中插入以下代码来检查文件大小。
if (typeofFileReader !== "undefined") {
// file[0] 是文件 1
var s = document.getElementById('myfile').files[0].size;
文件输入发生变化时,大小将会更新。为此,请使用事件监听器。
document.getElementById('input').onchange = function() {
// file[0] is file 1
var s = document.getElementById('input').files[0].size;
alert(s);
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

