在尝试上传到服务器之前,先在客户端验证文件大小。但是我认为我需要在javascript中计算最大大小。
那我怎么用JavaScript 写4MB呢?我还想基本了解javascript是根据文件大小计算的度量单位。
以下是我的感冒:
//Grab the file list
var files = e.target.files;
$.each(files,function(i,file){
//check for the correct file extensiton
var n = file.name,
s = file.size
t = file.type;
if(s > 4MB){
console.log("File is greater than 4MB");
}
}
Run Code Online (Sandbox Code Playgroud)
请帮忙。谢谢。
小智 5
文件大小以字节为单位-执行以下操作:
if (s > 4 * 1024 * 1024)
alert("Too big");Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3252 次 |
| 最近记录: |