jQuery $.fancybox.close() 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5192926/
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.close() not working
提问by saimaz
I know that question was discussed plenty of times, but i tried all suggestions and noone didn't work. I am using fancybox with href atribute where content is loading using ajax.
我知道这个问题已经讨论过很多次了,但我尝试了所有建议,但没有一个不起作用。我正在使用带有 href 属性的fancybox,其中使用ajax 加载内容。
$('a').fancybox(
{
href:'ajax/test.php',
titleShow:false
});
And in content i had custom close button
在内容中我有自定义关闭按钮
<a href="javascript:void(1)" title="close" onclick="$.fancybox.close()">Pirkti prekes</a>
And when i click that i got $.fancybox is undefined.
当我点击它时,我得到 $.fancybox 未定义。
采纳答案by Kimtho6
Instead of making a onclick it should look like
而不是进行点击它应该看起来像
$('a').click(function(){
$(this).fancybox.close();
});
回答by cusimar9
I'm not sure about the fancybox, but your href attribute should just be a '#' with a 'return false' at the end of your onclick handler.
我不确定fancybox,但你的href 属性应该只是一个'#',在你的onclick 处理程序的末尾带有一个'return false'。
回答by pnairn
I think your problem is because you're loading the ajax content into an iframe?
我认为您的问题是因为您将 ajax 内容加载到 iframe 中?
Try
尝试
<a href="javascript:;" onclick="parent.$.fn.fancybox.close();">Close</a>
Also, the following works for me as well when using the same selector that was used to initialize fancybox in my page header script.
此外,当使用在我的页眉脚本中用于初始化fancybox 的相同选择器时,以下内容也适用于我。
<a href="javascript:;" onclick="$('a.myclass').fancybox.close();">Close</a>
Where a.myclass was used as the selector for the fancybox as follows
其中 a.myclass 被用作fancybox 的选择器,如下所示
$("a.myclass").fancybox({
'frameWidth': 920,
'frameHeight': 705 //with whatever other attributes you want to define
});
EDIT: See the Fancybox Google Group http://groups.google.com/group/fancybox/browse_thread/thread/a6eaf87875b93829
编辑:请参阅 Fancybox Google Group http://groups.google.com/group/fancybox/browse_thread/thread/a6eaf87875b93829
回答by Oleg Beat
sometimes i have the same problem, and use:
有时我有同样的问题,并使用:
parent.$('body').fancybox.close();
or
或者
$('body').fancybox.close();
or
或者
$.fancybox.close();
回答by Hossein Hashemi
I use below code. It works generally
我使用下面的代码。它一般有效
$('.fancybox-close').click();