javascript 读取图片文件的大小
时间:2024-04-17 10:40:11
如下:
function checkAttachment(){
alert("here");
var attachmentArray = document.getElementsByTagName("input");
var attachmentSizeArray = document.getElementsByName("fileMaxSize");
var index = 0;
for (var i = 0; i < attachmentArray.length; i++){
var attachment = attachmentArray[i];
if (attachment.type=="file"){
if (!isPhoto(attachment.value)){
alert("上传的附件必须是相片.");
attachment.focus();
return false;
}
if (getFileSize(attachment) > 1024 * attachmentSizeArray[index].value){
alert("上传的附件不能大于" + attachmentSizeArray[index].value + "k.");
attachment.focus();
return false;
}
index++;
}
}
return true;
}
function getFileSize(fileObject){
var image=new Image();
image.dynsrc=fileObject.value;
return image.fileSize;
}
第一个方法是获取页面的所有file控件和对应file文件大小的限定,
重点是第二个方法,很巧妙的用一个image来解决,(*^__^*) 嘻嘻……
标签:javascript,图片大小
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现简单的2048小游戏
2023-04-18 07:19:25
![](https://img.aspxhome.com/file/2023/3/93583_0s.jpg)
AJAX简单应用实例-弹出层
2011-04-14 10:55:00
Python闭包的使用方法
2022-11-27 07:45:07
发布你的Python模块详解
2021-06-10 02:03:53
python多进程实现进程间通信实例
2023-01-30 10:39:35
Python字符串格式化
2023-08-19 20:27:44
Oracle数据库系统使用经验六则
2010-07-26 13:22:00
使用Python编写提取日志中的中文的脚本的方法
2023-12-14 16:04:44
![](https://img.aspxhome.com/file/2023/9/81849_0s.png)
使用OpenCV circle函数图像上画圆的示例代码
2021-03-12 17:30:41
pytorch索引查找 index_select的例子
2023-09-12 20:45:05
Python3 完全平方数案例
2022-01-03 03:38:37
python用selenium打开chrome浏览器保持登录方式
2022-02-19 10:28:08
![](https://img.aspxhome.com/file/2023/6/133306_0s.jpg)
php开启mysqli扩展之后如何连接数据库
2023-11-14 17:36:08
php开启openssl的方法
2023-11-14 06:52:51
从零开始学YII2框架(五)快速生成代码工具 Gii 的使用
2024-05-11 09:54:56
![](https://img.aspxhome.com/file/2023/9/125819_0s.png)
史上最简单的MySQL数据备份与还原教程(下)(三十七)
2024-01-25 06:03:33
![](https://img.aspxhome.com/file/2023/7/118227_0s.png)
Python中的异常类型及处理方式示例详解
2022-10-27 14:55:58
![](https://img.aspxhome.com/file/2023/4/117554_0s.jpg)
使用python实现对元素的长截图功能
2023-11-20 10:27:44
![](https://img.aspxhome.com/file/2023/3/63923_0s.png)
javascript 函数声明与函数表达式的区别介绍
2024-04-23 09:08:50
Python解析nginx日志文件
2023-09-07 18:22:09