在线等:为何图片载入时缩放失效?
有一个显示产品的页面,产品中有图片,本意是想图片大于一定尺寸自动缩小,但是下面这段代码,只有加入alert("hi");之后才会有效果,一旦去掉这句就不缩放,为什么呢?请高手帮帮我,在线等,急用.
<img id="ProImg" border=0 src="UploadFiles/2008911175547745.jpg" onload="javascript:zoomIt(this);">
<script language="Javascript">
function zoomIt(theImg)
{
alert("hi");
if (theImg.width>18){
theImg.width=18;
}
if(theImg.height>20){
theImg.height=20;
}
}
</script>
原来用的代码为:<img id="ProImg" border=0 src="UploadFiles/2008911175547745.jpg" onload="javascript:if(this.width>20)this.width=20;">
但是发现一样问题存在,只有在语句中加入alert("hi");之后才会实现缩放.
在线等!