事件处理jQuery unclick()和unbind()事件? [英] Event handling jQuery unclick() and unbind() events?
问题描述
我想将一个点击事件附加到按钮元素,然后删除它,但是我不能让unclick()或unbind()事件按预期工作。在下面的代码中,按钮是tan颜色,点击事件起作用。
I want to attach a click event to a button element and then later remove it, but I can't get unclick() or unbind() event(s) to work as expected. In the code below, the button is 'tan' colour and the click event works.
window.onload = init;
function init() {
$("#startButton").css('background-color', 'beige').click(process_click);
$("#startButton").css('background-color', 'tan').unclick();
}
如何从元素中删除事件?
How can I remove events from my elements?
推荐答案
没有这样的东西,如 unclick()
。你从哪里得到了?
There's no such thing as unclick()
. Where did you get that from?
您可以通过调用unbind从元素中删除单个事件处理程序:
You can remove individual event handlers from an element by calling unbind:
$("#startButton").unbind("click", process_click);
如果要删除所有处理程序,或者使用匿名函数作为处理程序,可以省略 unbind()
的第二个参数:
If you want to remove all handlers, or you used an anonymous function as a handler, you can omit the second argument to unbind()
:
$("#startButton").unbind("click");
这篇关于事件处理jQuery unclick()和unbind()事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!