2009-12-13 9 views
1

:JQuery와 바인딩 해제 방법

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

내 자바 스크립트는 다음과 같습니다 onclick 이벤트가 이미지에서 제거되지 않는 이유

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

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

나는 그것을 클릭 한 후 ?

답변

3

바인딩 해제는 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'); 
+0

html로 설정된 onclick 이벤트를 변경하는 가장 좋은 방법은 무엇입니까? – danwoods

+2

$ (callingImg) [0] .removeAttribute ("onclick"); – Marius