js校验图片大小尺寸
来源:互联网 发布:数控机床plc编程 编辑:程序博客网 时间:2024/05/22 08:16
<html xmlns=" http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>标题文档</title><script>UpLoadFileCheck=function(){ this.AllowExt=".jpg,.gif";//允许传文件类型 0无限制 每扩展名边要加"," 写字母表示 this.AllowImgFileSize=0;//允许传文件大小 0无限制 单位:KB this.AllowImgWidth=0;//允许传图片宽度 0无限制 单位:px(像素) this.AllowImgHeight=0;//允许传图片高度 0无限制 单位:px(像素) this.ImgObj=new Image(); this.ImgFileSize=0; this.ImgWidth=0; this.ImgHeight=0; this.FileExt=""; this.ErrMsg=""; this.IsImg=false;//全局变量 }UpLoadFileCheck.prototype.CheckExt=function(obj){ this.ErrMsg=""; this.ImgObj.src=obj.value; //this.HasChecked=false; if(obj.value=="") { this.ErrMsg="\n请选择文件"; } else { this.FileExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase(); if(this.AllowExt!=0&&this.AllowExt.indexOf(this.FileExt)==-1)//判断文件类型否允许传 { this.ErrMsg="\n该文件类型允许传请传 "+this.AllowExt+" 类型文件前文件类型"+this.FileExt; } } if(this.ErrMsg!="") { this.ShowMsg(this.ErrMsg,false); return false; } else return this.CheckProperty(obj); }UpLoadFileCheck.prototype.CheckProperty=function(obj){ if(this.ImgObj.readyState!="complete")// { sleep(1000);//秒使用图能完全加载 } if(this.IsImg==true) { this.ImgWidth=this.ImgObj.width;//取图片宽度 this.ImgHeight=this.ImgObj.height;//取图片高度 if(this.AllowImgWidth!=0&&this.AllowImgWidth<this.ImgWidth) this.ErrMsg=this.ErrMsg+"\n图片宽度超限制请传宽度于"+this.AllowImgWidth+"px文件前图片宽度"+this.ImgWidth+"px"; if(this.AllowImgHeight!=0&&this.AllowImgHeight<this.ImgHeight) this.ErrMsg=this.ErrMsg+"\n图片高度超限制请传高度于"+this.AllowImgHeight+"px文件前图片高度"+this.ImgHeight+"px"; } this.ImgFileSize=Math.round(this.ImgObj.fileSize/1024*100)/100;//取图片文件 if(this.AllowImgFileSize!=0&&this.AllowImgFileSize<this.ImgFileSize) this.ErrMsg=this.ErrMsg+"\n文件超限制请传于"+this.AllowImgFileSize+"KB文件前文件"+this.ImgFileSize+"KB"; if(this.ErrMsg!="") { this.ShowMsg(this.ErrMsg,false); return false; } else return true; } UpLoadFileCheck.prototype.ShowMsg=function(msg,tf)//显示提示信息 tf=false 显示错误信息 msg-信息内容 { alert(msg);}function sleep(num) { var tempDate=new Date(); var tempStr=""; var theXmlHttp= new ActiveXObject("Microsoft.XMLHTTP"); while((new Date()-tempDate)<num) { tempStr+="\n"+(new Date()-tempDate); try{ theXmlHttp.open("get","about:blank?JK="+Math.random(), false); theXmlHttp.send(); } catch(e){;} } //containerDiv.innerText=tempStr; return; } function c(obj){ var d=new UpLoadFileCheck(); d.IsImg=true; d.AllowImgFileSize=160; d.AllowImgWidth=10; d.AllowImgHeight=10; d.CheckExt(obj);}</script></head><body><input name="imagePhoto" type="file" onchange="c(this)"/></body></html>
0 0
- js校验图片大小尺寸
- js+css完美控制未知尺寸图片大小
- 用php或js获取图片大小,高宽尺寸.
- 上传图片时js验证图片大小、尺寸、格式
- JS获取图片的原始尺寸和上传图片大小
- JS控制图片大小(自动调整图片大小,图片保持相对尺寸)
- 压缩图片大小尺寸
- 更改图片大小,显示固定尺寸
- javascript获取图片大小和尺寸
- JAVA获取图片大小和尺寸
- JAVA获取图片大小和尺寸
- java获取图片大小和尺寸
- JAVA获取图片大小和尺寸
- JAVA获取图片大小和尺寸
- Asp.net获取上传图片大小的尺寸!
- 用opencv改变图片大小(像素、尺寸)
- IOS中各种图片大小尺寸汇总
- 用opencv改变图片大小(像素、尺寸)
- 分析师在组织中的作用
- CMake与Make
- 统计数据库中一条记录的条数
- ubuntu 使用笔记
- 怎么将pdf转换成word转换器在线
- js校验图片大小尺寸
- git中的文件冲突解决方法
- 单个mdf sqlserver 文件的数据库恢复
- 启动和关闭JBoss As 7.1.1脚本
- CodeForces - 383C Propagating tree(dfs + 线段树)
- Unix网络编程第一卷(第三版) 第一个程序运行成功
- map的用法
- 利用CMS网站设计和控制您的互联网网站
- Java基础语法