var img = null;
function OnUpload() {
//var id = parent.document.getElementById("baEntity.id").value;
var id = parent.key;
if (id == -1) {
alert("请先录入步骤一");
return false;
} else {
if (img)
img.removeNode(true);
img=document.createElement("img"); 
img.style.position = "absolute";
img.style.visibility = "hidden";
img.attachEvent("onreadystatechange",OnStateChange); 
            img.attachEvent("onerror",OnError);
document.body.insertAdjacentElement("beforeend", img);
img.src = $("#txtFile").val();

}
}
function OnError() {
alert("支持JPG,PNG,GIF,BMP,JPEG格式的图片上传!");
}
function OnStateChange(){
alert("dsdsd");
if (img.readyState != "complete")
return false;
if (CheckValidate()) {
if (img.fileSize < 5242880) {
document.forms[0].action = "FileUpload.do?uploadtype=1"+"&picturetype="+picturetype;
document.forms[0].submit();
} else {
alert("图片大小不能超过5M!");
return false;
}
}
}
function CheckValidate() {
var dirUrl = document.getElementById("txtFile").value;
if (dirUrl == null || dirUrl == "") {
alert('文件路径不能为空!');
return false;
} else
return IsValidateFile(dirUrl);
}

解决方案 »

  1.   

    Image对象没有onreadystatechange事件,有onload事件。
      

  2.   

    img.attachEvent("onreadystatechange",OnStateChange); 
    onreadystatechange是相应xmlHttpRequest.readyState的吧。
      

  3.   

    记得很久以前看过一个帖子,IE和火狐都有一个类似的事件。一个是判断其值是否为complete.一个是判断是否load,也类似onreadystatechange。汗。没什么印象了!