如何通过点击按钮关闭Fancybox

How to close Fancybox from a button click?

本文关键字:Fancybox 按钮 何通过      更新时间:2023-09-26

我知道这个问题有很多主题,但我没有找到我特定问题的答案。。。

参考常见问题解答,我们不得不使用其中一个来关闭fancybox。

$.fancybox.close();

parent.$.fancybox.close();

但这对我来说不起作用。

我使用AJAX类型的fancybox,请参阅以下内容:

  $('.fancybox2').fancybox({
            type: 'ajax',
            title: 'Admin',
            maxWidth    : 800,
            maxHeight   : 400,
            fitToView   : false,
            width       : '70%',
            height      : '70%',
            autoSize    : false,
            closeClick  : false,
            openEffect  : 'elastic',
            closeEffect : 'none',
        });

因此,点击一个按钮后,它会在fancybox中显示另一个页面。在这个页面中有一个按钮,代码如下:

<input type=button onclick="$.fancybox.close();" value="Save" style="margin-top:30px;" class=button>

您的onclick="$.fancybox.close();"没有看到您的主fancybox对象。试着做一些类似的事情

<input type="button" value="Save" style="margin-top:30px;" class="button closeFancybox">

在您的主文档中

$(function(){
    $(document).on('click','.closeFancybox',function(){
            $.fancybox.close();
    })
})

更新

请尝试在上模拟类似的行为https://jsfiddle.net我试过你们写的例子,效果很好。