<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>

解决方案 »

  1.   

    上面的朋友不错,但是使用中我发现了一些问题,就是有时候报告的不对。
    我做了修改。
    <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>
      

  2.   

    <%
    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>
      

  3.   

    都已经说啦.就是用在一个img对象中加一个标识,这个要是唯一的哦.
    然后通过属性width和height来读取就可以了.如果有问题.看一下你的img是否放在不同的容器中.比如在body,form,iframe这样的东西里.如果有.可以再加上相应的标识.
      

  4.   

    if(img.readyState!="complete")
    这个判断还应该在img的onreadystatechange事件中处理,否则不能总是得到正确的信息