html默认样式:
<div class="news_infos" id="newsp">
<p><img src="/static/wddqxz/img/default/default.png" data-src="images/v1.jpg" style="width:300px;height:100px"></p>
</div>
CSS:
.news_infos img { max-width: 650px;height:auto; }
js:
<script type="text/javascript">
var aImg=document.getElementById("newsp").getElementsByTagName('img');
for(var i=0;i<aImg.length;i++){
aImg[i].style.height="100%";
aImg[i].style.width="100%";
}
</script>
或者 方法二:
<script type="text/javascript">
var aImg=document.getElementById("newsp").getElementsByTagName('img');
for(var i=0;i<aImg.length;i++){
aImg[i].style.height="auto";
aImg[i].style.width="auto";
}
</script>
html更改后:
<div class="news_infos" id="newsp">
<p><img src="/static/wddqxz/img/default/default.png" data-src="images/v1.jpg" style="width:100%;height:100%"></p>
</div>
方法三 CSS:
.news_infos img { max-width: 650px;height:auto; }
@media only screen and (max-width: 480px) {
.news_infos img { width:100%; }
}