IE在提交时清除输入[type =" file"] [英] IE clears input[type="file"] on submit

查看:107
本文介绍了IE在提交时清除输入[type =" file"]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面(演示):

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script type="text/javascript" src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function() {
                $("#id_button").click(function(e) {
                    $("#id_file").click();
                });
            });
        </script>
    </head>
    <body>
        <form method="post" enctype="multipart/form-data" action="http://www.google.com/">
            <input type="file" name="file" id="id_file" />
            <input type="button" id="id_button" value="fake button" />
            <input type="submit">
        </form>
    </body>

</html>

如果
我点击假按钮打开浏览对话框,选择文件(我看到它在输入[type =file] ),而不是点击提交按钮,没有发布任何帖子,输入[type =file] 已清除。

if I open browse dialog via clicking "fake button", select file (I see it in input[type="file"]), than click submit button and no post happens, the input[type="file"] is cleared.

我应该更改什么才能使其正常工作?

What should I changed to get it work?

我得到了在IE8和IE10中出现此问题。

I get this problem in IE8 and IE10.

PS:文件输入将被隐藏,因此用户只能使用假按钮。

PS: file input will be hidden, so user will work only with fake button.

推荐答案

所有浏览器都有不同的行为,因为它们允许您从javascript中执行以编程方式单击文件输入的输入按钮。

All of the browsers have different behavior when it comes to what they allow you to do from javascript with regards to programmatically clicking the input button for file inputs.

我发现似乎跨浏览器工作的最佳解决方案是将不透明度设置为0(不要使用display:none)并将按钮放在输入下方,以便用户点击输入选择对话框的0不透明度输入。

The best solution I have found that seems to work cross browser is to set the opacity to 0 (do not use display:none) and put the button underneath the input, so the user clicks through the 0 opacity input to your button, thus firing the input select dialog.

关于造型的好写文件输入可以在这里找到: http://www.quirksmode.org/dom/inputfile.html

A good writeup on styling the file input can be found here: http://www.quirksmode.org/dom/inputfile.html

这篇关于IE在提交时清除输入[type =&quot; file&quot;]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆