1

要素から 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 が実際に定義されていることを確認しました。はい、アンバインドが呼び出される前にイベントがバインドされます。これがアンバインドです。(log は console.log(); の省略形です)

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

1 に答える 1

10

これは機能するはずです:

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

完全なバインド コードを投稿できますか? また、これは実行に実行されてい.mouseup()ますか?

.mouseup(func)はショートカットで.bind('mouseup', func)あるため、match unbind は.unbind('mouseup')(これにより、匿名関数だけでなく、すべてmouseupハンドラーがアンバインドされることに注意してください。特定のハンドラーを削除する場合は、名前付き関数が必要になります)。

于 2010-08-13T15:23:07.260 に答える