我正在尝试从元素中取消绑定 mouseup 事件。我已经尝试了以下但没有一个工作。
$('#myElm').unbind('mouseup');
$('#myElm').unbind('onmouseup');
$('#myElm').unbind('click');
如何取消绑定使用 $('#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 确实定义了。是的,在调用 unbind 之前绑定了事件。这是解绑。(log 只是我对 console.log() 的简写;)
log('cacheBgArea.length: ' + cacheBgArea.length);
cacheBgArea.unbind('mouseup');//TODO: fix this, not unbinding...