Unbind mouseup?

て烟熏妆下的殇ゞ 提交于 2019-12-08 06:28:16

问题


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');

How do you unbind an event assigned using $('#myElm').mouseup(function({...}); ???

Edit: Adding full code


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');
      }
   });

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...

回答1:


This should be working:

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

Can you post your complete bind code? Also, are you sure this is running after the .mouseup() ran?

.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).



来源:https://stackoverflow.com/questions/3478281/unbind-mouseup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!