请教下根据图片大小,判断当图片宽大于500px的时候图片宽缩小到500,高按比例缩放,宽小于500的时候原图显示,该怎么写?

解决方案 »

  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=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function() {
    var imgs = document.getElementById('container').getElementsByTagName('img');
    for(var i = 0; i < imgs.length; i ++) {
    if (imgs[i].width > 500) {
    imgs[i].width = '500';
    imgs[i].heigth = '';
    }
    }
    }
    </script>
    </head><body>
    <div id="container">
    <img src="http://res1.windows.microsoft.com/resbox/en/Windows%207/main/0e8c5cfc-9b44-4c4c-8cb2-c3cab50c908c_6.jpg" /><br />
        <img src="http://res2.windows.microsoft.com/resbox/en/Windows%207/main/b4697528-c130-4dec-a943-ac069fbbe238_8.jpg" />
    </div>
    </body>
    </html>