问题
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