1

私のHTMLが次のようになっている場合:

<div id="result_root" class="expand_image">
  <image id="expAllArtistImg" class="expImg" src="images/16-arrow-right.png" onclick="expand(this, 'artists', 'artists');"></image>
  <h1>All Artist</h1>
  </div>

私のJavaScriptは次のようになります。

//change arrow image
$(callingImg).attr("src","images/16-arrow-down.png");

//change arrow onClick function
$(callingImg).unbind('click');

クリックした後、onclickイベントが画像から削除されないのはなぜですか?

4

1 に答える 1

3

unbindは、jQueryによって追加されたイベントのみを削除します。つまり、これは機能します。

$(callingImg).bind("click", function(){expand(this, 'artists', 'artists')});

//And then sometime later:

//change arrow image
$(callingImg).attr("src","images/16-arrow-down.png");

//change arrow onClick function
$(callingImg).unbind('click');
于 2009-12-13T06:59:41.067 に答える