javascript Fancybox - 表单提交并关闭它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4758964/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fancybox - form submit and close it?
提问by Klauzito
I start my fancybox like code down
我像代码一样开始我的花式盒子
$('a.detail').click(function() {
   $.fancybox({
         'width'         : 750,
         'height'        : 520,
         'title'         : 'EDI??O DE SHOW',
   'titlePosition' : 'inside',
   'transitionIn' : 'fade',
   'transitionOut' : 'none',
   'href'          : 'templates/detail.php?id=<?php echo $tg_id['id'];?>',
   'type'          : 'iframe'  
   })
  })
and into myfancy, I got a form to update informations about schedules.
在我的幻想中,我得到了一个表格来更新有关时间表的信息。
$(function() {
   $("form#comment").submit(function() {
   var dat = $("#datepicker").val();
   var uf = $("#uf").val();
   var flr = $("input[name='flpic']:checked").val();
   var tit = $("#titulo").val();
   var mssg = $("#mensagem").val();
   var id = $("#id").val();
   if(BrowserDetect.browser == 'Explorer'){
    var nav = 'ie'
   } else {
    var nav = 'ot'
   }
   $.ajax({
             type: "POST",
             url: "edit_agenda.php",
             data: "id="+id+"&datepicker="+ dat+"&uf="+uf+"&fl="+flr+"&titulo="+tit+"&mensagem="+mssg+"&bro="+nav,
             success: function(){
      $("#status").html("<img src='../images/1-0.gif' alt='Enviando' />");
   **???? Can I call some function to close this fancy here?**   
              }
         });
      return false;
  });
 });
My question is:
我的问题是:
After submit this form, can I close this fancy within a function?
提交此表单后,我可以在函数中关闭此功能吗?
回答by qmerfp
$.ajax({
    type: "POST",
    url: "edit_agenda.php",
    data: "id="+id+"&datepicker="+ dat+"&uf="+uf+"&fl="+flr+"&titulo="+tit+"&mensagem="+mssg+"&bro="+nav,
    success: function(){
    parent.$.fancybox.close();
    }
});
回答by Klaster_1
回答by M M
Within an iframe
在 iframe 内
<input name="submit" type="submit" value="close" onClick="$.fancybox.close();" />
will also work.
也会起作用。
回答by Debashis Chowdhury
Use parent.$.fancybox.close();within the Iframe.
parent.$.fancybox.close();在 Iframe 内使用。
回答by Andrei
use this below script:
使用以下脚本:
parent.jQuery.fancybox.close();
回答by Mark
Try a PHP solution could try a simple rewrite in javascript if you want.
如果需要,尝试 PHP 解决方案可以尝试在 javascript 中进行简单的重写。
<?php
$close = 1;
if( $close) { echo ' <body onunload="self.close()"> ' ;} 
?>

