错误1:
onload="imgdisplay(this,90,90);",这必然是readyState == "complete",所以if(pimg.readyState == "complete" )这句没有意义
错误2:
pimg.width.这无法取值,应该是pimg.offsetWidth
错误3:
pimg.style.width=w;它应该取字符的值,所以应该是
pimg.style.width=w + "px"; 或
pimg.style.pixelWidth=w;

解决方案 »

  1.   

    参考一下这个:
    http://community.csdn.net/Expert/topic/4873/4873535.xml?temp=.1562921
      

  2.   

    是这个意思?function imgdisplay(pimg,iw,ih) {
    var img = new Image(); img.src=pimg.src;
    var w = iw;
    var h = ih;
    if(img.width >= iw && img.width > img.height)
    {
    h = img.height * iw / img.width;
    }
    else 
    {
    if(img.height >= ih) 
    {
    h = ih;
    w = img.width * ih / img.height;
    }
    } pimg.width=w;
    pimg.height=h;
    pimg.style.display="";
    }
      //]]>
      </script>
    <img src="http://zi.csdn.net/csdn20060705.gif" border="0" style="display:none" onload="imgdisplay(this,90,90);">
      

  3.   


    function  DrawImage(ImgD){
         w=120;
         h=100;
         var  image=new  Image();  
         image.src=ImgD.src;  
         if(image.width>0  &&  image.height>0){  
           flag=true;  
           if(image.width/image.height>=  w/h){  
             if(image.width>w){      
             ImgD.width=w;  
             ImgD.height=(image.height*w)/image.width;  
             }else{  
             ImgD.width=image.width;      
             ImgD.height=image.height;  
             }  
             ImgD.alt=image.width+"×"+image.height;  
             }  
           else{  
             if(image.height>h){      
             ImgD.height=h;  
             ImgD.width=(image.width*h)/image.height;            
             }else{  
             ImgD.width=image.width;      
             ImgD.height=image.height;  
             }  
             ImgD.alt=image.width+"×"+image.height;  
             }  
           }  
    }    
    ------------个性签名-------
    http://www.esoftnow.com/bbs
    技术论坛,欢迎光临!
      

  4.   

    new Image()是不是要重新加载一次图片? 这样会不会加重网络负担? 我提问的时候有网友用
    的offsetWidth和offsetHeight,我没有测试,不知道是不是可以得到图片的原始尺寸
      

  5.   

    我最终采用以下的代码,图片多时还不行,每页十个图片以下可以用!谢谢各位!
    function resizeImg(object,iw,ih){
    if(object.readyState=="complete"){
    var imgWidth=iw;
    var imgHeight=ih;
    var objImgWidth=object.offsetWidth;
    var objImgHeight=object.offsetHeight;
    var WidthHeightRate=objImgWidth/objImgHeight;
    //alert(WidthHeightRate);
    if(WidthHeightRate>1){
    imgWidth=imgWidth;
    imgHeight=imgWidth/WidthHeightRate;
    }
    if(WidthHeightRate==1){
    imgWidth=imgWidth;
    imgHeight=imgHeight;
    }
    if(WidthHeightRate<1){
    imgHeight=imgHeight;
    imgWidth=imgHeight*WidthHeightRate;
    }
    object.style.width=imgWidth;
    object.style.height=imgHeight;
    //object.style.display="";
    }
    }<img src="<%=rs_n("zhuang")%>" border="0" style="display:" onload="resizeImg(this,90,90);">
      

  6.   

    劳民伤财,不知道你为什么要这样做!<img src="<%=rs_n("zhuang")%>" width=90 height=90>
    浏览器就可以自动调整图片的显示大小为90x90<img src="<%=rs_n("zhuang")%>" width=90>
    浏览器就可以自动调整图片的显示宽度为90,高度按比例缩放
      

  7.   

    xuzuning(唠叨) :
    劳民伤财,不知道你为什么要这样做!<img src="<%=rs_n("zhuang")%>" width=90 height=90>
    浏览器就可以自动调整图片的显示大小为90x90<img src="<%=rs_n("zhuang")%>" width=90>
    浏览器就可以自动调整图片的显示宽度为90,高度按比例缩放------------------------这样的话也会按比例,但纠经是按高度的比例还是宽度的比例不好确定,哪高度数值大于宽度,还按宽度90的比例,表格就会被撑破了~~~~~