0

I am using JQuery .live to listen for a custom event, ie not .click, .change, .keyup or any of the native events, but rather an event that I create using jquery .trigger. I have several places in the application that listen for this event using .live. I want to remove a single handler from the event. None of the methods I've tried seem to work including, .unbind, .die, and .undelegate. I'm using jquery 1.6 so I can't use .off. What's the best way to accomplish this?

This is essentially the form my code takes. I call unbind first to remove the handler if it already exists.

OBJECT 1
{
    myNameSpace.MY_CUSTOM_EVENT_STRING = "my_event";

    $cachedFieldObject.trigger(myNameSpace.MY_CUSTOM_EVENT_STRING);
}

OBJECT 2
{
    function myfunctionName(var1) {myObject.myObjectsFunction()}

    $("#divID").find(".fieldClass").unbind(myNameSpace.MY_CUSTOM_EVENT_STRING, myfunctionName).live(myNameSpace.MY_CUSTOM_EVENT_STRING, myfunctionName);
}
4

1 回答 1

0

live()将委托的事件处理程序附加到文档元素,因此您必须将它们与文档元素解除绑定。这个小提琴展示了如何从实时但不特定的选定元素解除绑定特定功能。
编辑:
来自文档

  • 不支持链接方法。例如, $("a").find(".offsite, .external").live( ... ); 无效且无法按预期工作。

    可以取消绑定自定义事件,但您必须对所有绑定元素执行此操作
    在此小提琴中,自定义事件仅在所有元素都未绑定时才变为未绑定。

  • 于 2012-05-15T02:59:58.523 回答