事件处理jQuery unclick()和unbind()事件? [英] Event handling jQuery unclick() and unbind() events?

查看:261
本文介绍了事件处理jQuery unclick()和unbind()事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个点击事件附加到按钮元素,然后删除它,但是我不能让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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆