欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS檢測(cè)圖片大小的實(shí)例

 更新時(shí)間:2013年08月21日 15:41:10   作者:  
這篇文章介紹了JS檢測(cè)圖片大小的實(shí)例,有需要的朋友可以參考一下

復(fù)制代碼 代碼如下:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <input type="hidden" name="MAX_FILE_SIZE" id="MAX_FILE_SIZE" value="8000000" />

  <input type="file" name="files" id="files"   onchange="checkFileType(this)"/>
   <script type="text/javascript">
  var maxSize=document.getElementByIdx_x('MAX_FILE_SIZE').value;

function checkFileType(obj){

var path=obj.value.toString();

var perfix=path.substring(path.indexOf('.')+1);

var regExp=/(jpg|jpeg|gif|png)/gi;

if(perfix.match(regExp)){

checkFileSize(obj); //如果圖片文件類型匹配成功則執(zhí)行文件大小的檢測(cè)。

}else{

alert('對(duì)不起,請(qǐng)選擇圖片文件'); return false;

} }
function checkFileSize(obj){

var img=new Image();

try{

var imgSize=obj.files.item(0).fileSize;

return isLarged(imgSize,maxSize);//圖片文件大小比對(duì)。

}catch(e){ try{

img.src=obj.value;

return isLarged(img.fileSize,maxSize);

}catch(e){

obj.select();

var path=document.selection.createRange.text();

img.src=path;

return isLarged(img.fileSize,maxSize);

} } }
function isLarged(imgSize,maxSize){

if(imgSize>maxSize){

alert('對(duì)不起,您選擇的圖片文件超過(guò)了'+parseInt(maxSize/1024)+'Kb');

return false;

}else{

alert(parseInt(imgSize/1024)+ 'kb ' + 'This large is OK');

return true;

} } </script>

相關(guān)文章

最新評(píng)論