js实现图片自适应

<head>
<script type="text/javascript">
function ReImgSize(){   
           for (j=0;j<document.images.length;j++){              //遍历所有的图片 
                    document.images[j].width=(document.images[j].width>300)?"300":document.images[j].width; 
                    document.images[j].height=(document.images[j].height>200)?"200":document.images[j].height; 
               }  
}
</script>
</head>
<body onload="ReImgSize()">//当网页加载时,触发方法
<div style="border:1px solid black;width:310px; height:210px;">
<img src="01.jpg"/>
</div>
</body>
 
 
 
或者直接设置 图片的  max-width:100%,但是不兼容IE

posted on 2013-11-21 21:09  小刈  阅读(533)  评论(0编辑  收藏  举报

导航