//检测图片格式及大小 function checkImageSize(obj){ photoExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名 var ext_array = ['.jpg','.gif','.jpeg','.png']; if(!in_array(photoExt,ext_array)){ $(obj).val(''); tishi("您上传的图片格式有问题,请重新上传!"); return false; } var fileSize = 0; var isIE = /msie/i.test(navigator.userAgent) && !window.opera; if (isIE && !obj.files) { var filePath = obj.value; var fileSystem = new ActiveXObject("Scripting.FileSystemObject"); var file = fileSystem.GetFile (filePath); fileSize = file.Size; }else { fileSize = obj.files[0].size; } fileSize = Math.round(fileSize/1024/1024*100)/100; //单位为M if(fileSize>=2){ $(obj).val(''); tishi("您上传的图片大小超过2M,请重新上传!"); return false; } return true; }
js限制上传文件大小及类型
最新推荐文章于 2018-01-15 16:48:29 发布