<SCRIPT language=javascript>
function index_image_valid(){
document.pho_up.indeximg.src=document.pho_up.pho_index.value;
imagewidth=document.pho_up.indeximg.width;
imageheigth=document.pho_up.indeximg.height;
alert ("宽:"+imagewidth+"\n高:"+imageheigth);
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20" class=input Onchange="javascript:index_image_valid();">
<img name=indeximg>
</form>
function index_image_valid(){
document.pho_up.indeximg.src=document.pho_up.pho_index.value;
imagewidth=document.pho_up.indeximg.width;
imageheigth=document.pho_up.indeximg.height;
alert ("宽:"+imagewidth+"\n高:"+imageheigth);
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20" class=input Onchange="javascript:index_image_valid();">
<img name=indeximg>
</form>
我做了修改。
<SCRIPT language=javascript>
function index_image_valid(){
var img=new Image();
img.src=document.pho_up.pho_index.value;
imagewidth=img.width;
imageheigth=img.height;
fsize=img.fileSize/1024;
fsize=fsize.toFixed(1);
document.pho_up.cmd.disabled=true;
if(img.readyState!="complete")
window.setTimeout("index_image_valid()",10);
else
{alert ("宽:"+imagewidth+"\n高:"+imageheigth+"\n大小:"+fsize+" KB");
document.pho_up.cmd.disabled=false}
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20">
<input type=button name="cmd" value="测试图片大小" onclick="index_image_valid();">
</form>
Response.Write Request("a")
%>
<form method=post onsubmit="a.value=document.all.x.width + ':' + document.all.x.height">
<input name=a type=hidden>
<input type=file name=f onpropertychange='document.all.x.src=f.value'>
<input type=submit>
<img id=x style="visibility:hidden">
</form>
然后通过属性width和height来读取就可以了.如果有问题.看一下你的img是否放在不同的容器中.比如在body,form,iframe这样的东西里.如果有.可以再加上相应的标识.
这个判断还应该在img的onreadystatechange事件中处理,否则不能总是得到正确的信息