function DealWithImg() {
var width = 0;
if (window.screen.width) {
width = window.screen.width;
}
else if (window.innerWidth) { width = window.innerWidth; }
if (width > 0) {
var imgs = document.getElementsByTagName("img");
if (imgs.length > 0) {
for (var i = 0; i < imgs.length; i++) {
if (imgs[i].offsetWidth > width) {
imgs[i].style.width = "100%";
imgs[i].style.height = "auto";
}
}
}
}
}
window.onload = DealWithImg;
当图片html是后台传过来的时候(例如内容编辑的图片和文字转为html存在库里),控制图片的width:100%