复制代码 代码如下: <BR> var maxSize=document.getElementByIdx_x('MAX_FILE_SIZE').value; <br><br>function checkFileType(obj){<br><br>var path=obj.value.toString();<br><br>var perfix=path.substring(path.indexOf('.')+1);<br><br>var regExp=/(jpg|jpeg|gif|png)/gi;<br><br>if(perfix.match(regExp)){<br><br>checkFileSize(obj); //如果图片文件类型匹配成功则执行文件大小的检测。<br><br>}else{<br><br>alert('对不起,请选择图片文件'); return false;<br><br>} } <BR>function checkFileSize(obj){<br><br>var img=new Image();<br><br>try{<br><br>var imgSize=obj.files.item(0).fileSize;<br><br>return isLarged(imgSize,maxSize);//图片文件大小比对。<br><br>}catch(e){ try{<br><br>img.src=obj.value;<br><br>return isLarged(img.fileSize,maxSize);<br><br>}catch(e){<br><br>obj.select();<br><br>var path=document.selection.createRange.text();<br><br>img.src=path;<br><br>return isLarged(img.fileSize,maxSize);<br><br>} } } <BR>function isLarged(imgSize,maxSize){<br><br>if(imgSize>maxSize){<br><br>alert('对不起,您选择的图片文件超过了'+parseInt(maxSize/1024)+'Kb');<br><br>return false;<br><br>}else{<br><br>alert(parseInt(imgSize/1024)+ 'kb ' + 'This large is OK');<br><br>return true;<br><br>} }