jquery unbind方法

时间:2009-12-13 06:54:31

标签: jquery unbind

如果我的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事件?

1 个答案:

答案 0 :(得分: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');