【问题标题】:Issue with jQuery / iframe File Uploading SolutionjQuery / iframe 文件上传解决方案的问题
【发布时间】:2011-08-20 05:16:18
【问题描述】:

我最近为文件上传实现了一个 jQuery / iframe 解决方案,但遇到了一个相当烦人的问题(当然只在 IE 中)。

单击我的上传按钮并选择要上传的文件后,我会自动将包含该文件的表单提交到我的 iframe。但是 - 我需要单击页面上的任意位置,以便提交处理并触发我的控制器中的操作。

我认为 iframe 获得焦点是一个问题,这似乎阻止了“更改”功能完成执行,但我并不完全确定。 iframe 可能需要某种类型的 onload 函数才能将焦点返回到原始页面以继续执行?

代码:

表格和文件上传:

<form id="attachForm" action="<%= Url.Action("TestUpload","Images") %>" 
      method="post"  enctype="multipart/form-data" target='upload_target' >
        <input id='actualupload' type='file' multiple="" name='file' />
</form>
<iframe id='upload_target' name='upload_target' src='' 
        style="width:0; height: 0; border: 0;" frameborder="0"></iframe>

jQuery 提交表单:

$("#actualupload").live('change',function()
{
    $("#attachForm").submit();
    alert("Fired!"); //This only occurs after clicking on the screen after the 
                     //file selection.
});

【问题讨论】:

    标签: jquery asp.net asp.net-mvc file-upload uploading


    【解决方案1】:

    似乎.live() 导致了这种奇怪的行为。如果你使用即

    $(function() {
        $("#actualupload").change( function()
        {
            $("#attachForm").submit();
            alert("Fired!"); //This only occurs after clicking on the screen after the 
                             //file selection.
        });
    });
    

    它也适用于 IE。

    【讨论】:

      猜你喜欢
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 2013-10-25
      • 2012-11-08
      相关资源
      最近更新 更多