原因是你没有等到图片加载完成就执行后续操作了function CheckForm(theForm)
{
var fileext=theForm.zhaopian_up.value.substring(theForm.zhaopian_up.value.length-4,theForm.zhaopian_up.value.length)
fileext=fileext.toLowerCase() if (!(fileext=='.jpg' || fileext=='.png'))
{
alert("对不起,不正确的照片文件,必须为*.jpg或*.png文件 !");
theForm.zhaopian_up.focus();
return false;
} var s = document.form1.zhaopian_up.value;
if(s=="")return false;
var img = new Image();
img.onload = function() { fileSize=this.fileSize;}
img.src = s;
//  alert("高 = "+ img.height + "\n宽 = "+ img.width);
//  alert("fileSize = "+ img.fileSize +" 字节"); //这句如果不注释掉,就可以正常使用
document.write(fileSize);
if(img.fileSize>=1000)
{
alert("文件超出规定大小");
return false;
}
return true;
}

解决方案 »

  1.   

    多谢唠叨老大.....不过,同样一张图片,有时候就能过去,有时候,就过不去.按你的说法,是图片没有完全加载完.
    那..你当中加的img.onload = function() { fileSize=this.fileSize;}可以再延长一点时间吗?谢谢,再次感谢....
      

  2.   

    function CheckForm(theForm)
    {
    var fileext=theForm.zhaopian_up.value.substring(theForm.zhaopian_up.value.length-4,theForm.zhaopian_up.value.length)
    fileext=fileext.toLowerCase() if (!(fileext=='.jpg' || fileext=='.png'))
    {
    alert("对不起,不正确的照片文件,必须为*.jpg或*.png文件 !");
    theForm.zhaopian_up.focus();
    return false;
    } var s = document.form1.zhaopian_up.value;
    if(s=="")return false;
      flag = false;
    var img = new Image();
      img.onload = function() { fileSize=this.fileSize;flag=true;}
    img.src = s;
    //  alert("高 = "+ img.height + "\n宽 = "+ img.width);
    //  alert("fileSize = "+ img.fileSize +" 字节"); //这句如果不注释掉,就可以正常使用
      while(!flag)
      {
        ;//do nothing
      }
    document.write(fileSize);
    if(img.fileSize>=1000)
    {
    alert("文件超出规定大小");
    return false;
    }
    return true;
    }加个循环就可以了~