如果我的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事件?
答案 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');