<script> //此段代码用来重置文章内容中宽度超出范围的图片 window.onload = function() { var Article_Content_ID = "imga"; //文章内容所在的Div的ID var MAX_Width = 600; //最大图片宽度 var imgs = document.getElementById(Article_Content_ID).getElementsByTagName("img"); for ( var i = 0,len = imgs.length;i<len;i++ ){ if( parseInt(imgs[i].width,10) > MAX_Width ){ var iw = parseInt(imgs[i].width,10) ; var ih = parseInt(imgs[i].height,10) ; imgs[i].style.width = MAX_Width +"px"; imgs[i].style.height = parseInt( ih * MAX_Width / iw ) + "px"; } } } </script> <div id="imga" class="nr"><img src="1.jpg"></div>