当上传图片时,有时候需要控制下上传图片的尺寸大小,需要给个提示
//获取图片的尺寸,控制尺寸大小var reader = new FileReader(), img = new Image();// 选择的文件对象var file = null;$('#jjfxSoft_iconPath,#jjfxSoft_screenshotPath,#jjfxSoft_recommendPath').on('change', function (event) { file = event.target.files[0]; var excuteId = this.id; // 选择的文件是图片 if (file.type.indexOf("image") == 0) { reader.readAsDataURL(file); } // 文件base64化,以便获知图片原始尺寸 reader.onload = function(e) { img.src = e.target.result; // base64地址图片加载完毕后 img.onload = function(){ // 图片原始尺寸 var originWidth = this.width; var originHeight = this.height; // 最大尺寸限制 var maxWidth = 400, maxHeight = 400; // 图片尺寸超过400x400的限制 if (originWidth > maxWidth || originHeight > maxHeight) { dialogMsg("图片过大,请选择400*400以下的图片",0); $("#"+excuteId).val(""); return false; } }; };})