如何禁用facebox(jquery)

发布于 2024-09-13 21:31:43 字数 810 浏览 4 评论 0原文

我在某些链接上使用 Facebox 插件。

我想动态禁用一些链接。所以点击它们不会打开facebox。

我尝试了多种方法来做到这一点,但似乎都不起作用。单击链接时,Facebox 仍然有效。

我什至尝试过这个(防止单击和鼠标按下事件),但它仍然无法禁用弹出的脸框。

$('#who_button').click(function(event) {  event.preventDefault();});
$('#who_button').mousedown(function(event) {  event.preventDefault();});

我能做些什么?

编辑:

按照 Brad 和 PetersenDidIt 的建议,我尝试了这个:

$('#who_button').click(function(event) { alert ('here');event.stopPropagation(); event.stopImmediatePropagation();});
    $('#who_button').mousedown(function(event) { event.stopPropagation(); event.stopImmediatePropagation();});

但仍然没有运气。此外,我看到 Facebox 框架出现在警报对话框下方。这意味着 Facebox 在我的单击/鼠标按下事件被调用之前启动。

是否可以附加在所有其他事件之前发生的事件?

也许facebox 使用另一个事件(不是单击或鼠标按下)。它会是什么?

I use facebox plugin on certain links.

I want to disable some of the links dynamically. so clicking them will not open facebox.

I tried several ways to do it but none of them seem to work. Facebox still works when clicking on the links.

I even tried this (prevent the click and mouse down events) but it still doesn't disable the facebox from popping up.

$('#who_button').click(function(event) {  event.preventDefault();});
$('#who_button').mousedown(function(event) {  event.preventDefault();});

What can I do?

EDIT:

Following brad and PetersenDidIt advice I tried this:

$('#who_button').click(function(event) { alert ('here');event.stopPropagation(); event.stopImmediatePropagation();});
    $('#who_button').mousedown(function(event) { event.stopPropagation(); event.stopImmediatePropagation();});

AND still no luck. Moreover I see that the facebox frame appears under the alert dialog. which means that facebox starts before my click/mousedown events are even called.

Is it possible to attach event which will occur before all other events?

Perhaps facebox uses another event (not click or mousedown). what can it be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一紙繁鸢 2024-09-20 21:31:43

PreventDefault 只是阻止该单击的任何正常行为(即在链接上重定向)。

我从未使用过facebox,所以我不确定它如何绑定其事件,但您可能想要更多类似的东西:

event.stopImmediatePropagation()

编辑

看起来facebox使用它自己的自定义事件。您可以在源代码中看到这一点(如下)。因此,最好的选择是从该事件中解除元素的绑定:

$("ele").unbind("click.facebox");

Facebox public function

  $.fn.facebox = function(settings) {
    if ($(this).length == 0) return

    init(settings)

    function clickHandler() {
      $.facebox.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      fillFaceboxFromHref(this.href, klass)
      return false
    }

    return this.bind('click.facebox', clickHandler)
  }

preventDefault just prevents whatever the normal behaviour of that click is (ie redirect on a link).

I've never used facebox, so I'm not sure how it binds its events, but you probably want some thing more like:

event.stopImmediatePropagation()

EDIT

Looks like facebox uses it's own custom event. You can see this in the source (below). So your best bet is to unbind your element from that event:

$("ele").unbind("click.facebox");

Facebox public function

  $.fn.facebox = function(settings) {
    if ($(this).length == 0) return

    init(settings)

    function clickHandler() {
      $.facebox.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      fillFaceboxFromHref(this.href, klass)
      return false
    }

    return this.bind('click.facebox', clickHandler)
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文