UpH*_*lix 1 javascript jquery events onmouseup unbind
我试图解除一个元素的mouseup事件.我尝试了以下但没有一个正在工作.
$('#myElm').unbind('mouseup');
$('#myElm').unbind('onmouseup');
$('#myElm').unbind('click');
Run Code Online (Sandbox Code Playgroud)
如何取消绑定使用$('#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');
}
});
Run Code Online (Sandbox Code Playgroud)
我已经验证了cacheBgArea确实已经定义了.是的,事件在调用unbind之前绑定.这是解开的.(log只是我对console.log()的简写;)
log('cacheBgArea.length: ' + cacheBgArea.length);
cacheBgArea.unbind('mouseup');//TODO: fix this, not unbinding...
Run Code Online (Sandbox Code Playgroud)
这应该是有效的:
$('#myElm').unbind('mouseup');
Run Code Online (Sandbox Code Playgroud)
你能发布完整的绑定代码吗?另外,你确定这是运行后的.mouseup()
跑?
.mouseup(func)
为快捷方式.bind('mouseup', func)
,所以比赛取消绑定的.unbind('mouseup')
(注意,这解除绑定所有的的mouseup
处理程序,而不仅仅是匿名函数,你需要一个命名的功能,如果你想删除一个特定的处理程序).
归档时间: |
|
查看次数: |
7318 次 |
最近记录: |