取消绑定mouseup? [英] Unbind mouseup?
问题描述
我正在尝试从元素取消绑定mouseup事件.我已经尝试了以下方法,但是都无法正常工作.
I am trying to unbind the mouseup event from an element. I have tried the following but none are working.
$('#myElm').unbind('mouseup');
$('#myElm').unbind('onmouseup');
$('#myElm').unbind('click');
如何取消绑定使用$('#myElm').mouseup(function({...});分配的事件???
How do you unbind an event assigned using $('#myElm').mouseup(function({...}); ???
修改:添加完整代码
cacheBgArea.mouseup(function(){
var $cursorInElm = $(cacheBgArea.selectedText().obj);
var selectFontSize = parseInt($cursorInElm.css('fontSize')), selectFontFace = $cursorInElm.css('fontFamily');
$fontSizeSlider.slider('value', selectFontSize);
$chooseFontFace.find('option').each(function(){
var $this = $(this);
if ($this.val() == selectFontFace) {
$this.attr('selected', true);
return false;
}
});
log('font weight: ' + $cursorInElm.css('fontWeight'));
if ($cursorInElm.css('fontWeight') == 'bold' || $cursorInElm.css('fontWeight') == 401) {
$boldCheckbox.attr('checked', true).change();
} else {
$boldCheckbox.attr('checked', false).change();
}
var objText = cacheBgArea.selectedText();
if (objText.obj.nodeName == 'a' || objText.obj.nodeName == 'A') {
$cursorInElm = $(objText.obj)
var elmsHref = $cursorInElm.attr('href');
if (elmsHref && elmsHref != '#') {
$enterOwnLink.val(elmsHref).show();
$switchToPage.show();
$chooseLinkPage.hide();
$chooseLinkTitle.html('Enter a Web Address');
} else if ($cursorInElm.attr('linkPageId')) {
$chooseLinkPage.find('option').each(function(){
var $this = $(this);
if ($this.val() == $cursorInElm.attr('linkPageId')) {
$this.attr('selected', true);
return false;
}
});
$enterOwnLink.hide();
$switchToPage.hide();
$chooseLinkPage.show();
$chooseLinkTitle.html('Choose a Page');
}
} else {
$('#noneLink').attr('selected', true);
$enterOwnLink.hide();
$switchToPage.hide();
$chooseLinkPage.show();
$chooseLinkTitle.html('Choose a Page');
}
});
我已经验证过cacheBgArea确实已定义.是的,事件是在调用取消绑定之前绑定的.这是解除绑定. (日志只是我console.log()的简写).
I have verified that cacheBgArea in indeed defined. Yes, the event is bound before the unbind is called. This is the unbind. (log is just my shorthand for console.log();)
log('cacheBgArea.length: ' + cacheBgArea.length);
cacheBgArea.unbind('mouseup');//TODO: fix this, not unbinding...
推荐答案
这应该有效:
$('#myElm').unbind('mouseup');
您可以发布完整的绑定代码吗?另外,您确定在 .mouseup()
运行后 运行吗?
Can you post your complete bind code? Also, are you sure this is running after the .mouseup()
ran?
.mouseup(func)
是 mouseup
处理程序,而不仅仅是匿名函数,如果要删除特定的处理程序,则需要命名函数).
.mouseup(func)
is a shortcut for .bind('mouseup', func)
so the match unbind is .unbind('mouseup')
(note this unbinds all of the mouseup
handlers, not just the anonymous function, you'll need a named function if you want to remove a specific handler).
这篇关于取消绑定mouseup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!