0

我有一些 jquery 的问题,它适用于 chrome 和 firefox,但不适用于 IE

编码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js">
</script>
</head>

<body>

<form method='post' name='aform' action='test2.html'>
<input type='file' value='Upload Billede' name='image[fileupload]' /><input type='button' class='upload image[fileupload]' value='Upload Billede' />
</form>
<script type="text/javascript">
$(document).ready(function(){

bind_file_upload();    
});
function bind_file_upload()
{
    var target_id;
    $("[name='image[fileupload]']").change(function(event){
        $("[name='aform']").submit();
    });
    $(".upload").click(function(){
        $("[name='image[fileupload]']").click();
    });
}

</script>

</body>
</html>

问题是,当我通过浏览按钮直接使用文件控件时,页面提交,但是当我使用自己的上传按钮时,它会触发文件对话框,但是当我选择一个文件并按下打开 jquery 时,权限被拒绝。

我做错了什么。

提前致谢

4

2 回答 2

4

您的问题是,当您模拟单击文件输入时,IE 将表单标记为安全威胁,并且不会发送它。对于 IE,您必须让用户自己单击文件输入。

编辑

如果你真的想自定义文件输入,你可以考虑这个:http ://www.quirksmode.org/dom/inputfile.html

或者,您可以使用可以根据需要自定义的 flash/silverlight 插件,或者对于 Internet Explorer 使用 ActiveX 控件。

于 2012-10-26T08:41:41.477 回答
0

正如 Gregoire D. 所说,当用户不直接单击文件输入时,IE 会阻止您的表单提交。所以对于 IE 我使用下一个解决方案

http://www.quirksmode.org/dom/inputfile.html

那里提供了两种可能的解决方案。我更喜欢第一个(基于 CSS)的解决方案。

于 2013-06-25T08:56:09.770 回答