JS 判断 图片上传_限制格式、类型、尺寸
来源:互联网 发布:excel保存数据丢失 编辑:程序博客网 时间:2024/09/21 09:28
用HTML的File控件上传图片,用js判断和限制图片格式、类型、尺寸
//判断图片类型
var f=document.getElementById("File1").value;
if(f=="")
{ alert("请上传图片");return false;}
else
{
if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(f))
{
alert("图片类型必须是.gif,jpeg,jpg,png中的一种")
return false;
}
}
function CheckFile(f,p)
2{
3//判断图片尺寸
4var img=null;
5img=document.createElement("img");
6document.body.insertAdjacentElement("beforeend",img);
7img.style.visibility="hidden";
8img.src=f;
9var imgwidth=img.offsetWidth;
10var imgheight=img.offsetHeight;
11if(p.name=="UpFile_Photo1")
12{
13if(imgwidth!=68||imgheight!=68)
14{
15alert("小图的尺寸应该是68x68");
16}
17}
18if(p.name=="UpFile_Photo2")
19{
20if(imgwidth!=257||imgheight!=351)
21{
22alert("中图的尺寸应该是257x351");
23}
24}
25if(p.name=="UpFile_Photo3")
26{
27if(imgwidth!=800||imgheight!=800)
28{
29alert("大图的尺寸应该是800x800");
30}
31}
32//判断图片类型
33if(!/\.(gif|jpg|jpeg|bmp)$/.test(f))
34{
35alert("图片类型必须是.gif,jpeg,jpg,bmp中的一种")
36return false;
37}
38return true;
39}
1<input type="file" id="UpFile_Photo1" runat="server" name="UpFile_Photo1"
2size="35" onpropertychange="CheckFile(this.value,this)">小图<br />
3<input type="file" id="UpFile_Photo2" runat="server" name="UpFile_Photo2"
4size="35" onpropertychange="CheckFile(this.value,this)">中图<br />
5<input type="file" id="UpFile_Photo3" runat="server" name="UpFile_Photo3"
6size="35" onpropertychange="CheckFile(this.value,this)">大图<br />
- JS 判断 图片上传_限制格式、类型、尺寸
- JS 判断 图片上传_限制格式、类型、尺寸
- 用HTML的File控件上传图片,用JS判断和限制图片格式、类型、尺寸
- js限制上传图片的格式和尺寸
- JS判断限制上传文件(图片)类型
- js验证上传文件大小、图片类型限制
- 限制上传图片的尺寸
- FCKeditor限制图片上传尺寸
- 图片上传限制尺寸大小
- 上传图片js判断图片尺寸和格式
- js上传图片进行预览、验证格式及尺寸
- 上传图片时js验证图片大小、尺寸、格式
- js 异步上传图片 限制图片的格式大小
- 上传图片判断文件尺寸
- js上传文件(图片)限制格式及大小
- 图片上传。格式判断
- jS判断上传格式
- 上传图片前判断图片的尺寸
- Spark Streaming编程指南(一)
- windows系统脚本,exp导出备份,备份保留7天
- 1013. 数素数 (20)
- 基于matlab的huffman编解码
- linux-redis页面报500无法正常处理请求的方案
- JS 判断 图片上传_限制格式、类型、尺寸
- android中string.xml中%1$s、%1$d 的简单用法
- lua 在 windows 系统的环境配置
- 75-Sort Colors
- 动态规划训练8 [E
- 扫描识别控件Dynamic Web TWAIN v13.0发布,新增统一的Dynamsoft服务
- 请求网络数据过程中弹出框
- oracle数据库建立transTitle(俩个Function,一个Type)20170622
- OkHttp使用教程