jQuery 1.4 动态创建的图像纵横比在 IE8 和最大宽度中不正确

标签 jquery internet-explorer-8 jquery-1.4

升级到 jQuery 1.4 后,当我尝试在 IE8 中使用 jQuery 1.4 动态地将图像添加到页面时,图像将失去正确的宽高比。这似乎只影响 IE8(IE7 和 Firefox 工作正常)和 jQuery 1.4(1.3.2 工作正常)。包含 jQuery 兼容性文件并不能解决问题。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" language="javascript"
        type="text/javascript"></script>
    <!-- Switching to 1.3.2 fixes the problem -->
    <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" language="javascript"
        type="text/javascript"></script>-->
    <script type="text/javascript">
        $(document).ready(function() {
            var dynImg = $('<img></img>').attr('src', 'http://www.google.com/intl/en_ALL/images/logo.gif');
            $('body').append(dynImg);
        });
    </script>
    <style type="text/css">
        img
        {
            max-width: 5em;
        }
    </style>
</head>
<body></body></html>

最佳答案

设置 CSS zoom 属性:

img {
    zoom: 100%;
}

关于jQuery 1.4 动态创建的图像纵横比在 IE8 和最大宽度中不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2124259/

相关文章:

javascript - 如何在表单中仅发布用户选择的值

jquery $.post 在 Firefox 中不起作用

c# - 如何在 Windows Server 2008 的 IE8 中启用 ActiveX?

internet-explorer-8 - jQuery 的委托(delegate)与 IE 中的另一个委托(delegate)冲突

jquery 1.4.2 相当于 setTimeout 和clearTimeout

javascript - Webmethod 不适用于 jquery

javascript - 将 data-dismiss ="modal"绑定(bind)到按键单击

html - IE8 - CSS 可见性 : collapse - Doesn't work?

Bootstrap 3.1.1 中的 Html5shiv 库在 IE8 中不起作用

jQuery 1.4.2 : . 是 (":focus")给出语法错误