2014-02-13 2 views
2

페이지 안에는 두 개의 버튼이 있으며, 하나는 서버 (pdf)에서 문서를 검색하고 다른 하나는 현재 양식을 제출하는 "다음"버튼입니다.jQuery 클릭 이벤트가 끝난 후 액션 수행

사용자가 문서 다운로드를 완료 할 때까지 "다음"버튼의 바인딩을 해제하고 싶습니다.

내가 가지고있는 다음과 같은 기능 :

$.fn.unbindItem = function(){ 
    return this.each(function(){ 
     $(this).css('opacity', 0.5).css('cursor', 'not-allowed').unbind('click'); 
    }); 
}; 

$.fn.reBindItem = function(){ 
    return this.each(function(){ 
     $(this).css('opacity', 1).css('cursor', 'pointer').bind('click'); 
    }); 
}; 

그리고, 문서가 준비되면 : 분명히

$(document).ready(function(){ 
    ... 
    nextButton.unbindItem(); 

    //TEST 1 
    docButton.click(function(e){ 
    $.when(e).done(function(){ nextButton.reBindItem(); }); 
    }); 

    //TEST 2 
    $.when(docButton.click()).done(function(){ nextButton.reBindItem(); }); 

    //TEST 3 
    docButton.click().queue(function(){ 
    nextButton.reBindItem(); 
    $(this).dequeue(); 
    }); 

    //TEST 4 
    docButton.click().done(function(){ nextButton.reBindItem(); }); 
}); 

내가 동시에에 모든 경우를 테스트하지 않았 그러나 1 하나씩. nextButton 다시 자체를 결합하지만,

  • TEST 2 후 문서 관리자 창 는 메시지가 표시 될 수 있습니다 :

    • TEST 1 :

      각 테스트의 결과

      는 docButton 클릭 기능이 최대한 빨리 시작입니다 다음 관리자를 기록, 창 nextButton는
    • TEST 3 바인더 제본을 다시 한 후 메시지가 표시 될 수 있습니다 : 작동하지만 nextButton는
    • 을 rebinded 후 문서 관리자가 프롬프트를 표시하지
    • TEST (4)를 작동 않습니다
  • +0

    다운로드가 완료 될 때까지 다음 버튼을 숨길 수 있습니까? –

    +0

    nop, 버튼이 보이지만 클릭 가능하지 않아야합니다. – Wolfchamane

    +1

    다운로드가 완료 될 때까지 nextbutton에 "disabled"속성을 추가하고 jquery와 함께 다운로드하면 제거합니다 –

    답변

    1
    $.fn.unbindItem = function(){ 
        return this.each(function(){ 
         $(this).attr("disabled","disabled"); 
        }); 
    }; 
    
    $.fn.reBindItem = function(){ 
        return this.each(function(){ 
         $(this).removeAttr("disabled"); 
        }); 
    }; 
    
    관련 문제