[英]how to unbind event by jquery
if (IsBestanswer == "True")
{
$(bestAnswer).addClass('IsBestanswer');
$(bestAnswer).unbind('click');
}
bestAnswer.live('click', function()
{
// some code....
});
actually i want to disable click property on bestanswer while IsBestanswer == "True". 实际上,我想在IsBestanswer ==“ True”时禁用bestanswer的点击属性。 here i am using unbind() function.
在这里我正在使用unbind()函数。 but it's not working ...
但这不起作用...
is there any methode for disable like adding some css property ...actually i don't know.. 是否有任何禁用方法,例如添加一些CSS属性...实际上我不知道..
To unbind a live
handler, call die
. 要取消绑定
live
处理程序,请致电die
。 (I didn't make that up) (我没有弥补)
However, if bestAnswer
is a single element, there's no point in using live
instead of bind
. 但是,如果
bestAnswer
是单个元素,那么使用live
而不是bind
是没有意义的。
live
is designed to be used with a selector that will match elements in the future. live
设计为与将来会匹配元素的选择器一起使用。
Also, if you can write bestAnswer.live
, you don't need to write $(bestAnswer)
, since it's already a jQuery object. 另外,如果您可以编写
bestAnswer.live
,则无需编写$(bestAnswer)
,因为它已经是一个jQuery对象。
(As opposed to a DOM element, selector, or HTML string which you would need to call $
on) (与您需要调用
$
的DOM元素,选择器或HTML字符串相反)
You could just do it in your handler, no unbinding necessary: 您可以在处理程序中执行此操作,而无需解除绑定:
$("selector for answers here").live('click', function()
{
if (!$(this).hasClass("IsBestanswer")) {
// do something, this isn't the best answer
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.