如下: 复制代码 代码如下: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来解决,(*^__^*) 嘻嘻……
推荐阅读
PNG背景在不同浏览器下的应用
一、在IE6中使用PNG背景 IE6本身并不认识PNG图片的透明特性,虽然有让IE6支持PNG透明背景的JS程序: 复制代码 代码如下:function correctPNG() { var arVersion = navigator.appVersion.split("MSIE") var version>>>详细阅读
本文标题:javascript 读取图片文件的大小
地址:http://www.17bianji.com/kaifa2/JS/28554.html
1/2 1