gpt4 book ai didi

javascript - 解绑mouseup?

转载 作者:行者123 更新时间:2023-11-30 07:11:32 24 4
gpt4 key购买 nike

我正在尝试解除 mouseup 事件与元素的绑定(bind)。我尝试了以下方法,但均无效。

$('#myElm').unbind('mouseup');
$('#myElm').unbind('onmouseup');
$('#myElm').unbind('click');

如何取消绑定(bind)使用 $('#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 确实已定义。是的,在调用解除绑定(bind)之前绑定(bind)了事件。这就是解绑。 (日志只是我对 console.log(); 的简写)

log('cacheBgArea.length: ' + cacheBgArea.length);
cacheBgArea.unbind('mouseup');//TODO: fix this, not unbinding...

最佳答案

这应该有效:

$('#myElm').unbind('mouseup');

你能发布你完整的绑定(bind)代码吗?此外,您确定这是在 .mouseup() 之后运行吗?跑了?

.mouseup(func).bind('mouseup', func) 的快捷方式所以匹配解除绑定(bind)是.unbind('mouseup') (请注意,这会取消绑定(bind)所有 mouseup 处理程序,而不仅仅是匿名函数,如果要删除特定处理程序,您将需要一个命名函数)。

关于javascript - 解绑mouseup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3478281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com