2011-02-03 3 views
0

jQuery 함수를 만들어 페이스 박스 대화 상자에서 취소 또는 제거 버튼을 눌렀는지 확인하려고하는데, 어떻게해야하는지 잘 모르겠습니다. confirmDialog가 어디jQuery 클릭 선택기를 IF 문으로 전달합니다.

// Confirm and remove group members 
$("[id^='removeGroupMember_']").click(function() { 
     confirmDialog('Removal', 'Are you sure you want to remove this person from the group?'); 

     // I need to check the results of the confirm dialog prior 
     // to calling the code below to remove the actual rows 

     $(this).parent().slideUp("fast", function() { 
      $(this).remove(); 
      updateGroupRows(); 
     }); 
    return false; 
}); 

을 :

는 지금, 나는이

function confirmDialog(action, message) { 
    $.facebox('<h3 class="confirmHeader light tb">Confirm ' + action + '</h3><div class="confirmContent"><p>' + message + '</p><a href="#" id="dialogConfirmAction" class="ras small red button right">' + action + '</a><a href="#" id="dialogConfirmCancel" class="ras small gray button right">Cancel</a></div>'); 
}; 

지금 내가 그 버튼을 누를 때 두 가지 기능을 가지고,하지만 난 모르겠어요 방법 결과를 확인하고 그 피드를 다시 가져와 관련 행을 삭제할지 여부를 결정할 수 있습니다.

$('#dialogConfirmAction').live('click', function() { 
    console.log('Yep... they dun clicked it.'); 
    return true; 
}); 

$('#dialogConfirmCancel').live('click', function() { 
    $.facebox.close(); 
    return true; 
}); 

제공 할 수있는 모든 지침을 매우 높이 평가합니다!

답변

1

당신이 당신의 confirmDialog 기능을 변경 할 일은 원하는 것은과 같이 될 : 당신은 다음으로 "행동에"일이 원하는 것을 전달할 수

function confirmDialog(action, message, actionfunc) { 
    $.facebox('<h3 class="confirmHeader light tb">Confirm ' + action + '</h3><div class="confirmContent"><p>' + message + '</p><a href="#" id="dialogConfirmAction" class="ras small red button right">' + action + '</a><a href="#" id="dialogConfirmCancel" class="ras small gray button right">Cancel</a></div>'); 
    if(actionfunc) { 
     $('#dialogConfirmAction').click(actionfunc); 
    } 
}; 

함수를 confirmDialog 함수에 전달합니다.

$("[id^='removeGroupMember_']").click(function() { 
    var $that = $(this); 
    confirmDialog('Removal', 'Are you sure you want to remove this person from the group?', 
        function() { 
         //This function will be run when the "action" link is clicked 
         $that.parent().slideUp("fast", function() { 
          $(this).remove(); 
          updateGroupRows(); 
         }); 
        }); 
    return false; 
}); 

을 그리고 당신은 취소에 무엇을 말할 수있는 또 다른 변수를 추가하여 그것을 확장 할 수 있습니다 : 이것은 다른 코드를 보면 다음과 같이 만들 것입니다.

+0

처음 게시했을 때 오타가 발생했습니다. confirmDialog 함수의 선택기는 취소 버튼입니다. 나는 그것을 고쳤다. –

+0

나는 거대한 맥주 하나를 당신에게 빚지고있다. 본질적으로 콜백 함수를 만들었습니까? 그건 그렇고,'$ (this) .parent() '를 호출하면 원래 목록 항목 대신 모달 상자를 호출한다는 의미이므로 선택자를 캐싱하기 시작했습니다. – iwasrobbed

+0

@iWasRobbed : 네, 기본적으로 제가 한 일입니다. 그리고, 죄송합니다. 하하 그냥 원래 클릭 기능에서 새 기능으로 작업을 복사했습니다. 완전을 기하기 위해 그것을 편집 할 것입니다. ** 수정 ** 고정! –

-1

이 시도 :

// Confirm and remove group members 
$("[id^='removeGroupMember_']").click(function() { 

     if(confirmDialog('Removal', 'Are you sure you want to remove this person from the group?')) { 
      // I need to check the results of the confirm dialog prior 
      // to calling the code below to remove the actual rows 

      $(this).parent().slideUp("fast", function() { 
       $(this).remove(); 
       updateGroupRows(); 
      }); 
     } 
    return false; 
}); 
+0

죄송합니다. 작동하지 않습니다. – iwasrobbed

+0

@ user341652 :'confirmDialog'는 a)'confirm()'함수와 같지 않고 b) 함수가 모달이 아닌 팝업을 만들어서 아무런 방법이 없기 때문에 이것은 작동하지 않습니다 호출 함수에 true 또는 false를 올바르게 반환 할 수 있습니다. –

관련 문제