<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>MyHtml.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=gbk">
    
  <script type="text/javascript">
function clearFilename(filename){
var imgvalue=document.getElementById("uploadphoto").value; 
var imgsrc=document.getElementById("jcrop_target"); 
imgsrc.src=filename;
checkImgWH();
}
function checkImgWH(){
//alert('1');
 var imgobj=document.getElementById("jcrop_target");
 var imgheight=480;
var imgwidth=640;

//alert(""+imgobj[0].src+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗");
 if(imgobj.width!=imgwidth||imgobj.height!=imgheight){
   alert("图片像素要求宽:640 高:480 该图片的宽="+imgobj.width+" 高="+imgobj.height+" 请重新拍照");
   //if(confirm("图片像素要求宽:"+imgwidth+" 高:"+imgheight+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗")){
  //document.getElementById("savebutton").disabled=true;
   //}
  }
  else{
 // document.getElementById("savebutton").disabled=false;
  }

</script>
  </head>
  
  <body>
  <input class="mywidget" type="file" name="uploadphoto" id="uploadphoto" size="50"  
onchange="clearFilename(this.value);" />
<img  src="C:\vehdigital1\xiyan.jpg" id="jcrop_target" name="jcrop_target" />
  </body>
</html>

解决方案 »

  1.   

    <input class="mywidget" type="file" name="uploadphoto" id="uploadphoto" size="50"   
    onchange="clearFilename(this.value);" />
    type="file"可以跟type=submit的效果是一样的,点击以后都是提交表单。
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <title>MyHtml.html</title>  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
      <meta http-equiv="description" content="this is my page">
      <meta http-equiv="content-type" content="text/html; charset=gbk">
        
      <script type="text/javascript">
    function clearFilename(filename){var imgsrc=document.getElementById("jcrop_target");  
    imgsrc.src=filename;alert(filename);alert(imgsrc.width);
    //checkImgWH();
    }
    function checkImgWH(){
    //alert('1');
    var imgobj=document.getElementById("jcrop_target");
    var imgheight=480;
    var imgwidth=640;//alert(""+imgobj[0].src+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗");
    if(imgobj.width!=imgwidth||imgobj.height!=imgheight){
    alert("图片像素要求宽:640 高:480 该图片的宽="+imgobj.width+" 高="+imgobj.height+" 请重新拍照");
    //if(confirm("图片像素要求宽:"+imgwidth+" 高:"+imgheight+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗")){
    //document.getElementById("savebutton").disabled=true;
    //}
    }
    else{
    // document.getElementById("savebutton").disabled=false;
    }
    }  
    </script>
      </head>
       
      <body>
      <input class="mywidget" type="file" name="uploadphoto" id="uploadphoto" size="50"   
    onchange="clearFilename(this.value);" />
    <img src="C:\vehdigital1\xiyan.jpg" id="jcrop_target" name="jcrop_target" />
      </body>
    </html>
    你这样试一下,感觉是速度太快了,所以还是替换前的图片宽度
      

  3.   

    <img src="C:\vehdigital1\xiyan.jpg" id="jcrop_target" name="jcrop_target" onload="alert(this.width)"/>
    用img的加载事件来 输出就是最新的图片长宽了
      

  4.   

    需要在onload之后再进行获取,不过IE里面再次从缓存里面获取的时候不一定会调用onload,有另外一个属性
    onreadstatechange为complete