简体   繁体   English

如何禁用Facebox(jQuery)

[英]how to disable facebox (jquery)

I use facebox plugin on certain links. 我在某些链接上使用facebox插件。

I want to disable some of the links dynamically. 我想动态禁用某些链接。 so clicking them will not open facebox. 因此单击它们将不会打开Facebox。

I tried several ways to do it but none of them seem to work. 我尝试了几种方法来完成此操作,但似乎没有一种有效。 Facebox still works when clicking on the links. 单击链接时,Facebox仍然有效。

I even tried this (prevent the click and mouse down events) but it still doesn't disable the facebox from popping up. 我什至尝试了此操作(防止了click和mouse down事件),但仍然不能阻止面板弹出。

$('#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: 遵循brad和PetersenDidIt的建议,我尝试了以下操作:

$('#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. 这意味着Facebox在我的click / mousedown事件被调用之前就开始了。

Is it possible to attach event which will occur before all other events? 是否可以附加将在所有其他事件之前发生的事件?

Perhaps facebox uses another event (not click or mousedown). 也许facebox使用了另一个事件(不是单击或鼠标按下)。 what can it be? 会是什么

preventDefault just prevents whatever the normal behaviour of that click is (ie redirect on a link). preventDefault仅阻止该点击的正常行为(即,重定向到链接)。

I've never used facebox, so I'm not sure how it binds its events, but you probably want some thing more like: 我从未使用过facebox,因此不确定它如何绑定其事件,但是您可能想要一些类似的东西:

event.stopImmediatePropagation()

EDIT 编辑

Looks like facebox uses it's own custom event. 看起来Facebox使用了它自己的自定义事件。 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 Facebox公共功能

  $.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)
  }

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

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