简体   繁体   English

Facebox只能使用一次

[英]Facebox only works once

Am binding my Facebox requests just how the documentation says on the Facebox website. 绑定我的Facebox要求文档在Facebox网站上的说明。

But after I click one of the div.comment's the Facebox request doesn't work again. 但是,当我单击div.comment之一时,Facebox请求不再起作用。

The code I am using is just below and further down is my error. 我正在使用的代码在下面,而更进一步的是我的错误。

$(document).ready(function() {
    $('.comment').bind('click', function() {
        $.facebox({ajax: '/project/cake_app/comment/tweets/' + $(this).attr('id')});
    }); 
});

Error: 错误:

Uncaught TypeError: Object function (a,b){return new d.fn.init(a,b,g)} has no method 'facebox'

The reason Kim's suggestion to replace the bind() with live() didn't work is because the problem is not that the original click event handler gets lost. Kim建议用live()替换bind()无效的原因是因为问题不是原来的click事件处理程序丢失了。

As the error suggests: 如错误所示:

Uncaught TypeError: Object function (a,b){return new d.fn.init(a,b,g)} has no method 'facebox'

The problem is that the jQuery $ object loses the .facebox() method. 问题在于jQuery $对象丢失了.facebox()方法。 Facebox works fine closing and reopening the window EXCEPT when you load jQuery INSIDE the facebox. 当您在面盒中加载jQuery时,Facebox可以很好地关闭并重新打开窗口(除)。 Doing that reinitializes jQuery after facebox has already been loaded, so facebox doesn't have a chance to re-add itself to the jQuery $ object when jQuery reinitializes. 这样做会在Facebox已加载后重新初始化jQuery,因此在jQuery重新初始化时,facebox没有机会将自身重新添加到jQuery $对象中。

I solved this problem by removing jQuery from the code which loads in the facebox. 我通过从加载在Facebox中的代码中删除jQuery解决了这个问题。 If jQuery is already loaded on the main page, then it is in the environment and there is no need to load it again inside the facebox code. 如果已经在主页上加载了jQuery,则说明它已在环境中,因此无需在facebox代码中再次加载它。 This is only an issue if you rely on jQuery in both your main page AND in the code inside the facebox. 仅当您在主页和面板中的代码中都依赖jQuery时,这才是问题。 I suppose if you HAVE to load jQuery again inside the facebox, you can use a seperate instance by using jQuery.noConflict(). 我想,如果您必须再次在面板中加载jQuery,则可以通过使用jQuery.noConflict()使用单独的实例。

have you tryed using live like: 您是否尝试过像这样的现场直播:

$(document).ready(function() {
    $('.comment').live('click', function() {
        $.facebox({ajax: '/project/cake_app/comment/tweets/' + $(this).attr('id')});
    }); 
});
$(document).ready(function() {
    $('.comment').bind('click', function() {
        $.facebox({ajax: '/project/cake_app/comment/tweets/' + $(this).attr('id')});
$(".comment").unbind('click');
    }); 
});

hope that it works 希望它能起作用

我通过从Facebox切换到Fancybox解决了我的问题,看来他们是Facebox的错误,该错误在使用一次后便解除了绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM