Cancel jQuery event handling

后端 未结 4 1687
萌比男神i
萌比男神i 2021-02-14 12:36

I have setup onclick event handler in the following manner:

element.onclick = function() { /*code */ }

Imagine there are event handlers setup u

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-14 13:14

    Jquery has a method for namespacing events. http://docs.jquery.com/Namespaced_Events

    You can add, trigger and remove separate functions bound to the same event via namespaces:

    $("a").bind("click.custom1",function(){ ... });
    $("a").bind("click.custom2",function(){ ... });
    $("a").trigger("click.custom2");
    $("a").unbind("click.custom2");
    

    As long as you unbind the namespaced event your normal onclick should be unaffected. You may have to bind two separate namespaces to the click event as above if that doesn't work.

提交回复
热议问题