<td width=200 ><img src='' id='pic'></td>

解决方案 »

  1.   

    <script language="JavaScript"> 
    <!-- 
    //图片按比例缩放 
    var flag=false; 
    function DrawImage(ImgD){ 
     var image=new Image(); 
     var iwidth = 80;  //定义允许图片宽度 
     var iheight = 80;  //定义允许图片高度 
     image.src=ImgD.src; 
     if(image.width>0 && image.height>0){ 
     flag=true; 
     if(image.width/image.height>= iwidth/iheight){ 
      if(image.width>iwidth){   
      ImgD.width=iwidth; 
      ImgD.height=(image.height*iwidth)/image.width; 
      }else{ 
      ImgD.width=image.width;   
      ImgD.height=image.height; 
      } 
      ImgD.alt=image.width+"×"+image.height; 
      } 
     else{ 
      if(image.height>iheight){   
      ImgD.height=iheight; 
      ImgD.width=(image.width*iheight)/image.height;   
      }else{ 
      ImgD.width=image.width;   
      ImgD.height=image.height; 
      } 
      ImgD.alt=image.width+"×"+image.height; 
      } 
     } 
    }  
    //--> 
    </script> 
    <img src=".." onload = "DrawImage(this)">
      

  2.   

    我有好多z张要在 pic这个id里显示,每张大小都不一样
      

  3.   

    function img(src)
    {
    var image=new Image(); 
    image.src = src;
    var w0 = image.width;
    var h0 = image.height;
    var w1 = 200;
    var h1 = 300;
    var r0 = w1/w0;
    var r1 = h1/h0; if(r0>r1) r0 = r1;
    w0 = w0*r0;
    h0 = h0*r0; pic.style.width = w0;
    pic.style.height = h0;
    pic.src = src;
    }