问题
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?
回答1:
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)
}
回答2:
Try event.stopPropagation()
来源:https://stackoverflow.com/questions/3450709/how-to-disable-facebox-jquery