-1

我在这里有一个较早的帖子,但答案根本没有帮助。我有这样的上传功能:

<iframe class="iframe" name="message" src="upload.php" style="display:none;"></iframe>
<form action="upload.php" method="post" enctype="multipart/form-data" target="message">
    Select a file: <input type="file" name="upload">
    <input type="submit">
</form>

我正在尝试做这样的事情:

$('.iframe').fancybox({
    'hideOnContentClick': true
});

因此,当 upload.php 给出响应(“文件成功上传”)时,它会进入 iframe,这很棒。但我需要 iframe 来显示。upload.php 回复消息后如何取消隐藏 iframe?

4

1 回答 1

0

你真的必须有一个内联 iframe 吗?您可以尝试submit通过 ajax 表单并在 fancybox 中显示响应,而无需像内联 iframe

<form id="uploadForm" action="upload.php" method="post" enctype="multipart/form-data" target="message">
    Select a file: <input type="file" name="upload">
    <input type="submit">
</form>

请注意,我在表单中添加了一个ID,以便我们可以通过该选择器对其进行操作。然后是 jQuery :

$("#uploadForm").bind("submit", function() {
 $.ajax({
   type     : "POST",
   cache    : false,
   url      : "upload.php",
   success  : function(data) {
    $.fancybox(data.responseText,{
      'hideOnContentClick': true
    });
   }
 });
 return false;
});
于 2012-10-03T19:01:38.703 回答