jQuery remove click event handler from an element

一世执手 提交于 2020-01-06 19:48:31

问题


I have this event handler,

$('#table_product').on 'click', '.th1',(event) ->
       $(this).unbind("click") #Not working

What I'm trying to achieve is when a user triggers this event, it will disable/detach the click event handler from .th1. So it won't give any response to the user for the next request.

Currently, I have tried unbind() and off(), but still no luck.. Any other suggestion ?


回答1:


First, it could be useful if you give us more code, so we can test the code easily.

From the API of jQuery:

$("#table_product").click(function() {

}

And from the answer of another question on SO:

$('.th1').off('click');

Perhaps this will help?




回答2:


Try using "live" to bind the event and use "die" to unbind.

$('#table_product').live( "click", '.th1',(event)

$('#table_product').die( "click", foo );


来源:https://stackoverflow.com/questions/24571846/jquery-remove-click-event-handler-from-an-element

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