第一种方法

<script language="javascript" type="text/javascript" >
function    DrawImage(ImgD,width,height){  
       var    image=new    Image();  
       image.src=ImgD.src;  
       if(image.width>0    &&    image.height>0){  
         if(image.width/image.height>=    width/height){  
           if(image.width>width){      
           ImgD.width=width;  
           ImgD.height=(image.height*width)/image.width;  
           }else{  
           ImgD.width=image.width;      
           ImgD.height=image.height;  
           }  
           }  
         else{  
           if(image.height>height){
           ImgD.height=height;  
           ImgD.width=(image.width*height)/image.height;            
           }else{  
           ImgD.width=image.width;      
           ImgD.height=image.height;  
           }  
           }  
         }  
}
</script>

 

onload="DrawImage(this,300,300)"

第二种方法:

<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
   flag=true;
   if(image.width/image.height>= 140/140){
    if(image.width>140){
     ImgD.width=140;
     ImgD.height=(image.height*140)/image.width;
    }else{
     ImgD.width=image.width;
     ImgD.height=image.height;
    }
    ImgD.alt="点击查看详细信息...";
   }
   else{
    if(image.height>140){
     ImgD.height=140;
     ImgD.width=(image.width*140)/image.height;
    }else{
     ImgD.width=image.width;
     ImgD.height=image.height;
    }
    ImgD.alt="点击查看详细信息...";
   }
}
}
//-->
</script>

 

onload="javascript:DrawImage(this);

posted on 2008-08-04 10:12  『程序开发』  阅读(257)  评论(0编辑  收藏  举报