页面中存在<img src="/images/logo.gif" />这样一段,请修改一下并加入脚本,当此图片加载完毕后,判断其宽度是否超过500px,若超过则将图片宽度设置为500px,否则保持原来大小。
<img src="/images/logo.gif"> onload="javascript:InitImage(this)"
<script lange="javascript">
function InitImage(imgObj)
{
}
</script>

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title><script lange="javascript"> 
    window.onload = function(){
    var img = document.getElementById('img');
    alert(img.width);
    if(img.width > 500){

    img.width = 500;
    }
    };
    </script>
    </head><body>
    <img src="未命名2.jpg" id="img" />  
    </body>
    </html>
      

  2.   

        if(img.width > 500){
                
                img.width = 500;
            }
    css width:expression(width>500?"500":auto);
      

  3.   

    这个onload事件不灵敏,我查阅的需要借助修改setTimeOut来加载图片,希望是楼上两位写的这么简单。