1

有什么方法可以在 IE 中实现 fileReader()。我搜索了很多,但没有找到任何解决方案。这是我试图实现它的代码。它在 Firefox 和 chrome 中运行良好,但在 IE8 和 IE9 中无法正常工作。

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <script>
        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#img_prev')
                        .attr('src', e.target.result)
                        .width(150)
                        .height(200);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
        </script>

        <meta charset=utf-8 />
        <title>JS Bin</title>
        <!--[if IE]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <style>
        article, aside, figure, footer, header, hgroup,
        menu, nav, section { display: block; }
        </style>
    </head>
    <body>
        <input type='file' onchange="readURL(this);" />
        <img id="img_prev" src="#" alt="your image" />
    </body>
</html>
4

1 回答 1

0

是的,我只有一个解决方案。IE 9 不支持文件阅读器,因此我们可以为其他浏览器禁用文件阅读器的图像预览,它将完美运行。

于 2013-02-20T02:57:34.797 回答