img=document.createElement("img"); 
当执行到这一句时,如果图片的文件大于10KB的话,是需要一点加载时间才能正确的获取img.fileSize的值。
<script>
var   img   =   null; 
function getsize()
{   
    var   local   =   document.getElementById("filSelect").value; 
    var   point   =   local.lastIndexOf("."); 
    var   type   =   local.substr(point).toUpperCase();     if(type   ==  ""){ 
    return   true; 
    } 
    else   if(   type   ==  ".JPEG"   ||   type   ==  ".JPG"   ||   type   ==  ".GIF"   )
    { 
    
        img   =   document.createElement("img");     
        img.src   =   local; 
        alert(img.fileSize);//立即获取时为-1
        setTimeout("alert(img.fileSize);",1000);//延迟一定时间后再获取,得到正确的大小值
        if(img.fileSize   >   2*1024*1024   )
        {          alert("Error1"); 
        return   false; 
        } 
        else
        { 
            return true; 
        } 
    } 
    else 
    { 
        alert("Error2");   return   false; 
    } 
}
</script>