在图片上传前,怎么用JS检查图片的大小长宽?

RT~~求js在图片上传前验证大小长宽的详细代码

  • star65225692 - 1年前

    <html> 
    <head> 
    <script. language="javascript" type="text/javascript"> 
    function getimginfo() 
    { 
    var img=new Image(); 
    img.src=document.all.file.value; 
    var sInfo="Width:"+img.width+ 
    "px Height:"+img.height+ 
    "px Size:"+getsizestring(img.fileSize); 
    alert(sInfo); 
    } 
    function getsizestring(len) 
    { 
    var kb=len/1024; 
    if(kb<1024) 
    return kb.toFixed(2)+"K"; 
    else 
    { 
    var m=kb/1024; 
    return m.toFixed(2)+"M"; 
    } 
    } 
    </script> 
    </head> 
    <body> 
    <table width="90%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td> 
    <img width="60" height="60" id="picdemo"> 
    </td> 
    <td> 
    <input type="file" id="file" nchange="document.all.picdemo.src=this.value" class="allinput">  
    <input type="submit" name="Submit" value="上传" nClick="getimginfo();"> 
    </td> 
    </tr> 
    </table> 
    </body> 
    </html>