2017-10-22 16 views
0

논리 값으로 돌아가, 내가 함수로 확인 방법을 포장 그래서 그것을마다 시간 https://jsfiddle.net/8g0j4unj/의 jQuery confirm.js이 결과는 내가이 <a href="https://craftpip.github.io/jquery-confirm/#confirm" rel="nofollow noreferrer">plugin</a>을 사용하고

function askQuestion($msg){ 
    $.confirm({ 
     icon : 'fa fa-question-circle-o', 
     content : ''+$msg+'', 
     theme : 'supervan', 
     closeIcon: true, 
     animation: 'scale', 
     type: 'orange', 
     draggable:'true', 
     buttons:{ 
      'Continue' : { 
       keys : ['enter'], 
       action : function(){ 
        return 1; 
       } 
      }, 
      'Cancel': { 
       keys : ['esc'], 
       action: function(){ 
        this.close(); 
       } 
      } 
     } 
    }); 
} 

을 사용할 수 있습니다 어떤 행동을하지만 프로세스를 계속하는 경우, 사용자가 조건을 확인하거나 취소 할 때 어떻게 함수를 부울로 반환 할 수 있습니까? 이 동안이 플러그인을 수행 할 callback 기능을 가지고 쉽게 사용할 수있는 이유

$(document).on('click','.sample',function(){ 
    if(askQuestion('Are you sure want to continue without adding a server') == 1){ 
       alert('Confirmed'); 
      } 
    else{ 
     alert('Cancelled'); 
    } 

}); 
+0

으로 간단하게 검색 할 수 있습니다. – Titus

+0

"return true"또는 "false false"에 대해 어떻게 생각하십니까? –

+0

@ sachinkumar 나는 벌써 작동하지 않았다. –

답변

0

는 정말 아무 생각이 없습니다. 당신은 사용자 Confirm 또는 Cancel 버튼을 클릭하면 감지하려고, 그래서 당신은이를 사용할 필요가 없습니다 :

$(document).on('click','.sample',function(){}); 

그리고 당신의 코드를 완전히 잘못 당신이 버튼을 클릭에 함수에서 반환 된 데이터를 얻을 싶어하기 때문에! 하지만 이걸로?

askQuestion('Are you sure want to continue without adding a server') 

실제로 아무 것도 반환하지 않습니다. 어쨌든. 당신은 당신`askQuestion` 기능이 (가)`상태 if` 항상 'FALSE'이 될 것이라는 점을 의미한다 아무것도 반환하지 않습니다 callback

function askQuestion($msg){ 
    $.confirm({ 
     icon : 'fa fa-question-circle-o', 
     content : ''+$msg+'', 
     theme : 'supervan', 
     closeIcon: true, 
     animation: 'scale', 
     type: 'orange', 
     draggable:'true', 
     buttons:{ 
      'Continue' : { 
       keys : ['enter'], 
       action : function(){ 
        alert('Confirmed'); // if clicked on confirm 
       } 
      }, 
      'Cancel': { 
       keys : ['esc'], 
       action: function(){ 
        this.close(); 
        alert('Canceled'); // if clicked on cancel 
       } 
      } 
     } 
    }); 
} 

JSFiddle