YUI: find event handlers for a node

佐手、 提交于 2019-12-24 06:45:28

问题


I want suspend the click event for a node temporally .

I want to get the click event handler for a node and detach it and then reattach it when i want it again.

I am using YUI 3.

Can some one tell me how could i query the click event handlers for a node and detach them ?


回答1:


See Y.Event.getListeners - http://yuilibrary.com/yui/docs/api/classes/Event.html#method_getListeners

For all the various ways you can detach events, see http://yuilibrary.com/yui/docs/event/#detach-methods




回答2:


on() returns a subscription object that can be used to unbind that subscription

var subscription = myNode.on("click", handleClick);

//unbind the subscription
subscription.detach();

Or you can use the Node's detach() method if you didnt get the subscription object

myNode.detach("click", handleClick); //detaches only handleClick

or if you want to dettach all click handlers :

node.detach('click');



来源:https://stackoverflow.com/questions/9391093/yui-find-event-handlers-for-a-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!