Javascript 在IE中使用JS调整图像大小时出错

Javascript 在IE中使用JS调整图像大小时出错,javascript,css,image,internet-explorer,cross-browser,Javascript,Css,Image,Internet Explorer,Cross Browser,我使用javascript调整图像的加载大小。下面的代码在chrome和firefox中非常有效,但在InternetExplorer11(或任何版本)中都不起作用 下面是调用JS函数的html段: <figure id="image-container"> <img id="image" onload="imgWidth()" src="http://www.nasa.gov/sites/default/files/styles/full_width_feature/

我使用javascript调整图像的加载大小。下面的代码在chrome和firefox中非常有效,但在InternetExplorer11(或任何版本)中都不起作用

下面是调用JS函数的html段:

<figure id="image-container">
    <img id="image" onload="imgWidth()" src="http://www.nasa.gov/sites/default/files/styles/full_width_feature/public/thumbnails/image/pia21376d.jpg" title="This image of a crescent Jupiter and the iconic Great Red Spot was created by a citizen scientist (Roman Tkachenko) using data from Juno's JunoCam instrument." />
</figure>

这是chrome中显示的Web空间的图像。

请注意,它会根据左侧容器的宽度调整大小。代码还会裁剪图像,使其在容器内垂直对齐。


id“image”对应于img标记,而“image container”对应于img标记周围的figure元素

我再次尝试使我的代码与IE兼容。
下面是IE中图像加载的方式:

我最终用jQuery替换了现有的javascript,现在它可以工作了

例如,而不是

document.getElementById('homework').offsetWidth;
document.getElementById('image').style="width: "+(940-width)+";";
我曾经

$("#homework").outerWidth();
而不是

document.getElementById('homework').offsetWidth;
document.getElementById('image').style="width: "+(940-width)+";";
我曾经

$("#image").css("width",(940-width));