2

I have a library function, that I cannot change, which uses MooTools to attach an event.

$(document.body).addEvents({
    "mousedown:relay(a.className)": function (a, b) {
        if (!a.rightClick) {
            //do something
        }
        return false
});

I'm not too familiar with MooTools, but I've tried everything I can think of to override this with a jQuery.click() event.

I've tried attaching a listener to .className, its parents (a few levels up), and even the whole body; each time, I use function (e) { e.preventDefault() } in my click event.

I've always assumed the preventDefault() would always prevent all default events associated with the newly-triggered event.

Can anyone enlighten me as to why my event override isn't working?

// EDIT

I'm not looking to use MooTools because we will probably port everything to jQuery (or at least not MooTools) in the future. I guess I'll have to, though, if there's no other way.

// EDIT 2

I've tried jQuery.off() in several different ways, including $j('body').off('click mousedown','.className'); and it still fails to remove the MooTools event.

// EDIT 3

I decided it was best to just not mess with MooTools; I've changed the classname so the MooTools doesn't do anything and just replicated what happened in the //do something part of the code above.

I have a feeling I can't do anything with the click event because of the return false at the end of the MooTools event listener.

4

1 回答 1

1

根据您使用的 JQuery 版本,您可以尝试off(JQuery 1.7 或更高版本)或unbind删除 MooTools 事件处理程序。

我不确定它们是如何在幕后工作的,但我认为无论它们是如何绑定事件的,它们都会删除事件处理程序。然后,您可以使用 JQuery 应用您自己的事件处理程序。

http://api.jquery.com/off/

http://api.jquery.com/unbind/

于 2013-03-14T15:30:13.943 回答