无法更改宽度+;用javascript实现图像的高度

无法更改宽度+;用javascript实现图像的高度,javascript,image,internet-explorer-8,internet-explorer-9,Javascript,Image,Internet Explorer 8,Internet Explorer 9,我动态上传我的照片。 我的代码也应该为IE9运行,在下面的代码中,我只关注IE9: <!doctype html> <html> <head> <!-- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> --> <link href='http://fonts.googleapis.com/css?fa

我动态上传我的照片。 我的代码也应该为IE9运行,在下面的代码中,我只关注IE9:

    <!doctype html>
    <html>
    <head>
    <!-- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> -->
    <link href='http://fonts.googleapis.com/css?family=PT+Sans:400italic' rel='stylesheet' type='text/css'>  
    <link href='http://fonts.googleapis.com/css?family=PT+Sans' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=PT+Sans:700' rel='stylesheet' type='text/css'>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
    <title>Image preview example</title>
    <script type="text/javascript">
    var loadImageFile = (function () {
        if (navigator.appName === "Microsoft Internet Explorer") {
            return function () {
                $("#id_image").width(300);
                $("#id_image").height(300);
                $("#id_image").css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image)");
                document.getElementById("id_image").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.getElementById("imageInput").value;
$("#id_image").width(320); // ****** Problematic line
$('#id_image").height(350); // ****** Problematic line
            }
        }
    })();
    </script>
    <style type="text/css">
    </style>
    </head>

    <body>

    <form name="uploadForm">
    <p><input id="imageInput" type="file" name="myPhoto" onchange="loadImageFile();" /><br />
    </form>
    <img id="id_image" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D" onmousedown="return false" alt="Your picture"/>
    </body>
    </html>

图像预览示例
var loadImageFile=(函数(){
如果(navigator.appName==“Microsoft Internet Explorer”){
返回函数(){
$(“#id_图像”)。宽度(300);
$(“id#U图像”)。高度(300);
$(“#id_image”).css(“过滤器”,“progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image)”;
document.getElementById(“id_image”).filters.item(“DXImageTransform.Microsoft.AlphaImageLoader”).src=document.getElementById(“imageInput”).value;
$(“#id_图像”)。宽度(320);/*******有问题的行
$(“#id_图像”)。高度(350);/*******有问题的行
}
}
})();

  • 为什么我必须在行之前声明宽度+高度: document.getElementById(“id_image”).filters.item(“DXImageTransform.Microsoft.AlphaImageLoader”).src=document.getElementById(“imageInput”).value

  • 我无法将行(标记在星号上:***有问题的行),因为它不会更改宽度+高度

  • 如何更改宽度+高度


    谢谢:)

    更改图像大小时会有延迟,直到屏幕上的图像大小发生变化


    你可以认为这个问题是关闭的。请把一个运行代码粘贴在JSFIDD雷上,我不理解你的意思。我的代码只是一个示例代码,我有问题要写它。这就是为什么我要问这个论坛。我需要改变JavaScript代码之后的宽度+高度,但是我不知道应该写什么。调试和查看WH。ats错误我希望看到一个正在运行的版本,现在只看它可能是一行“if(navigator.appName==”Microsoft Internet Explorer),返回一个函数但不执行它看起来很有趣设置css有效吗<代码>$(“#id_image”).css({宽度:320,高度:350})$(“#id_图像”)。css也做同样的事情。。。很抱歉我也没有复制代码。我已更改:sizingMethod=缩放为sizingMethod=图像。我不想把画面拉长。事实上,我所做的是把它放在帧中:300x300。我知道最大尺寸(宽度或高度)是多少,并分别计算出300/宽度或300/高度的比率。宽度和高度都乘以相同的比率,因此其中一个是300,另一个更小。为此,我首先需要“知道”原始图像的大小。一般来说,我是通过输入width=“auto”和height来实现的=