无法通过jQuery提交输入文件的动作更改

时间:2012-03-13 03:31:33

标签: html dhtml

我想在点击一个div时上传一个图片,它在ff,chrome,safari中没关系但是没有使用IE,我不知道为什么?请帮我!感谢。

这是我的代码:

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $('#photo_box').click(function() {
                $('.upload_button').click();
            });

            $('input[name=f_img]').change(function(event) {
                $('#frm_upload').submit();
            });
        });
    </script>
</head>
<body>
<div style="width:100; height: 200px; border:1px solid red;" id="photo_box">Click here</div>
<form id="frm_upload" name="frm_img" method="post" enctype="multipart/form-data" style="position: absolute; left: -1000000px; top: -10100000px; opacity: 0;" target="ifr_img">
    <input type="file" class="upload_button" name="f_img"/>
</form>
<iframe id="ifr_img" name="ifr_img" style="width:200px; height:200px; border: 1px solid blue;"></iframe>
</body>

1 个答案:

答案 0 :(得分:0)

由于 bobince 解释here,它取决于您使用的版本和浏览器,大多数IE版本都不允许这样做(虽然我不确定IE9)。

您可以尝试使用transparency technique或基于Flash的方法,例如Uploadify for jQuery。