console
function knowImgSize(id) {
var idWidth = $(id).width(),
idHeight = $(id).height();
$(id + ' img').each(function(index,img){
var img_w = $(this).width(),
img_h = $(this).height();
if(img_w > idWidth) {
var height = img_h * idWidth / img_w;
$(this).css({"width":idWidth, "height":height});
}
});
}
$(function(){
knowImgSize("#demo1");
});
<img src="http://pic.haoanyi.cn/pic/20160928/m_d6e9a091cf89383172905bb0e532f38d.jpg" width="1060" height="300" alt="">
<div id="demo1">
<img src="http://pic.haoanyi.cn/pic/20160928/m_d6e9a091cf89383172905bb0e532f38d.jpg" alt="">
</div>
#demo1{width:800px;height:300px;overflow:hidden;}