2011-02-27 7 views
3

현재 제목 상자를 기반으로하는 프로젝트 슬러그를 만들기 위해 jQuery 슬러그 플러그인을 사용하고 있습니다. 이것은 잘 작동합니다. 내가 troube를하고있는 것은 사용자가 편집 링크를 클릭 할 때만 슬러그를 업데이트하는 것입니다. 편집 링크가 호출 될 때 슬러그 기능이 시작되고 제대로 작동하지만 "완료"링크를 클릭하면 슬러그 기능을 끌 수있는 방법을 찾아야합니다. 나는 그것이 의미가 있기를 바랍니다.클릭시 jquery 함수를 종료하는 방법

$('#edit_slug').click(function() { 
    //allow user to edit the project slug 
    $("#edit_project_name").stringToSlug({ //this is the slug plugin 
     getPut: '.project_slug', 
     hide: false 
    }); 
    $('input.project_slug').show(); //show the input 
    $('input.project_slug').next("span").remove().end(); //remove the span with the slug 
    $('#edit_slug').hide(); //hide edit link 
    $('input.project_slug').after(" <a href='#' id='done_edit_slug'>Done</a>"); //show done link 
}); 

//if the user is done editing the slug show the span with the slug in it 
$('#done_edit_slug').live('click', function() { 
     $("#edit_project_name").stringToSlug().end(); //my attempt to make the function end 
     $('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>"); //show the slug as a span 
     $('input.project_slug').hide(); //hide the input box 
     $('#done_edit_slug').remove().end(); //remove done link 
     $('#edit_slug').show(); //show edit link 


}); 

저는 이것이 최선을 다하는 가장 좋은 방법이라고 확신하지 않습니다. 가장 중요한 것은 #done_edit_slug을 클릭하면 stringToSlug() 기능을 종료하는 방법을 알 수 없습니다.

감사합니다.

+0

false를 반환합니다. ? – delphist

답변

1

완료 이벤트 핸들러에서 텍스트 상자의 이벤트를 바인딩 해제하십시오.

$('#done_edit_slug').live('click', function() { 
     $("#edit_project_name").unbind("keyup keydown blur"); 
     $('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>"); 
     $('input.project_slug').hide(); 
     $('#done_edit_slug').remove().end(); 
     $('#edit_slug').show(); 
}); 

이것은 플러그인 소스의 기본 이벤트를 사용한다고 가정합니다.

+0

Welp, 쉬웠다! 고마워, 나는 여전히 jQuery에 비교적 익숙하지 않다. – BandonRandon