【问题标题】:Jquery Live with facebox pluginJquery Live with facebox 插件
【发布时间】:2011-01-19 23:50:35
【问题描述】:

我正在尝试将 jquery facebox 插件与实时事件一起使用(官方实现,而不是插件)。

我的主页通过 ajax 加载到一个页面中。该远程页面还具有指向我想在弹出对话框中显示的其他远程页面的链接。为此,我一直在使用 facebox 插件。

下面的代码不起作用,只是将远程页面加载到视口中一个新页面,而不是弹出窗口。

<script type="text/javascript">
            jQuery(document).ready(function($) {

                $('a[rel*=facebox]').live("click", function() {
                    $('a[rel*=facebox]').facebox()
                });
            });
          </script> 

这是使用现场活动的正确方法吗?

遗憾的是,我的开发机器只包含 IE6[:(],所以我不能使用 firebug 来调试代码。

【问题讨论】:

    标签: ajax facebox jquery


    【解决方案1】:

    用 fabrik 评论补充 Kobi 的答案:

    $('a[rel*=facebox]').live("mousedown", function() { 
        $(this).unbind('click'); //everytime you click unbind the past event handled.
        $(this).facebox();
    });
    

    所以,你可以防止 facebox 增加事件。

    感谢科比。

    【讨论】:

      【解决方案2】:

      我猜click 事件来不及启动 facebox。
      这可能适用于mousedown(在我的测试中似乎还可以,但并不完全相同)

      $('a[rel*=facebox]').live("mousedown", function() { 
          $(this).facebox(); // this should do, you don't need all links
      });
      

      我也会推荐这个。我建议在完成 AJAX 调用后激活 facebox:

      // sample code - you might use an other AJAX call
      $('#dynamicDiv').load('...', {}, function(){
          $('#dynamicDiv a[rel*=facebox]').facebox();
      });
      

      【讨论】:

      • 这个正在发射 facebox n+1 次。每次点击,facebox 都会自我繁殖。
      【解决方案3】:

      非常感谢,我遇到了麻烦,因为在加载我的动态内容后 rel=facebox 似乎根本不起作用

      我只是“重新激活”

      jQuery(文档).ready(函数($) { $('a[rel*=facebox]').facebox() })

      在 ajax.response 和瞧瞧之后,我可以看到弹出的 facebox 而不是链接中的页面。

      非常感谢科比。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-14
        • 2010-09-14
        • 1970-01-01
        • 1970-01-01
        • 2011-01-20
        • 1970-01-01
        相关资源
        最近更新 更多