日期:2014-05-16  浏览次数:20338 次

图片按比例缩小带来的ALT问题
Java code
<script language="JavaScript"> 
<!-- 
//图片按比例缩放 
var flag=false; 
function DrawImage(ImgD){ 
 var image=new Image(); 
 var iwidth = 165;  //定义允许图片宽度 
 var iheight = 165;  //定义允许图片高度 
 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>


HTML code
<a href="View.asp?id=<%=rs("id")%>" target="_blank"><img src="Manage/UpLoad/UpLoadImages/<%=rs("url")%>" border="0" width="165" height="165" onload ='DrawImage(this)' alt="<%=rs("name")%>" /></a>


图片按比例缩小后,ATL无法正常显示"<%=rs("name")%>",转而显示了图片的尺寸宽x高。如何修改才能让ATL正常显示标题?

------解决方案--------------------
你的代码明明重现设置alt当然会显示你设置的值
ImgD.alt=image.width+"×"+image.height;