1

完成“文件选择”后,我需要提交我的上传文件表格。
我的文件输入是,

<input type="file" id="myfile" name="myfile" />

我的表格是

<form id="uploadform" action="includes/upload_img.php" ......">

我正在使用这种方法:

  • 我正在动态创建表单和 i-frame(通过图像点击 - img.sendimage)
  • 执行选择文件对话框(在表单中创建)
  • 通过 PHP 将选定的文件发送到目录和
  • 显示返回的消息

但是,当我触发“选择文件对话框”并选择一个文件时,表单正在(立即)提交而没有选择文件。

我的代码如下所示:

$("img.sendimage").live('click',function(){
    $('<form id="uploadform" action="includes/upload_img.php" method="post" enctype="multipart/form-data" target="uploadframe" style="position: absolute;top: -1000px;">
    <input type="file" id="myfile" name="myfile" />
    <input type="submit" value="Submit" />
    <iframe id="uploadframe" name="uploadframe" src="includes/upload_img.php" width="0" height="0" scrolling="no" frameborder="0" style="visible:false;"></iframe>
    </form>').appendTo("body");
    $('#myfile').click();
    $('#uploadform').submit();
});

#myfile 输入关闭(并且文件也被选中)后,如何触发表单提交事件?

注意:如果我在单独的单击事件上使用相同的方法(例如;单击一个按钮以选择一个文件,然后单击另一个以发送选定的文件),则没有问题。它正在工作,但是当我立即触发事件时,没有成功。

马上谢谢。。

4

1 回答 1

0

我已经用那个解决方案解决了我的问题。

于 2012-06-22T19:01:37.850 回答