2013-10-11 2 views
0

jQuery를 처음 사용합니다. 맞춤 메시지 상자를 사용하고 있습니다. 나는 jQuery.msgBox()을 사용했다. 내가 비동기 적으로 호출하는 다음 두Syncronous jquery 호출 - jquery 메서드가 실행될 때까지 기다리는 방법?

function myFunction(){ 

    $.msgBox({ 
     title:"Custom Alert", 
     content:"Hello World!" 
    }); 

    /* some code goes here */ 
    // For example 
    alert("executing after Custom Alert.."); 
} 

처럼 사용하는 것을 시도하고있는 동안, 모두 팝업이 쇼를 가지고 지금

지금 내가 jQuery를의 첫 번째 블록이 먼저 실행 얻을하려면, 다음 경고 상자가해야 보여 주다.

어딘가에 내가 읽은 스크립트는 비동기식이므로 동 기적으로 호출 할 수있는 솔루션이 있습니다.


예이 성공/콜백 함수 .. 하지만 난 우리의 기본 '확인()'처럼 그래서 같이 작동한다 방법

var r=confirm("Press a button!") 
if (r==true) 
    { 
    alert("You pressed OK!") 
    } 
else 
    { 
    alert("You pressed Cancel!") 
    } 

을하고 싶은 뭔가를 사용하여 수행 할 수 있습니다 ... 내가 좋아하는 그것을 호출 할 때

function myConfirm(message){ 

$.msgBox({ 
    title: "Confirmation !!", 
    content: message, 
    type: "confirm", 
    buttons: [{ value: "Yes" }, { value: "No" }], 
    success: function (result) { 
     if (result == "Yes") { 
      return true; // kindly...i dont know this is proper way to return value.. 
     }else{ 
      return false; // kindly...i dont know this is proper way to return value.. 
     } 
    } 
    }); 
} 

이제 .. 내가

var r = myConfirm("What do u like to choose?"); 

/* some operation will do on 'r' */ 
/* also to continue to next operation*/ 
처럼 원하는

그런 다음 반환 값에서 다음 작업을 수행합니다. 사용자 정의 myConfirm() 상자 메소드가 기본 confirm() 메소드처럼 작동하도록 할 수 있습니다.

답변

2

다음을 시도해보십시오. 성공 함수 안에주의를 기울여 확인하십시오.

$.msgBox({ 
    title:"Custom Alert", 
    content:"Hello World!", 
    success: function() { 
     alert("executing after Custom Alert..!"); 
    } 
}); 
+0

감사합니다. Saranya !! 이 방법 중 하나입니다 ...하지만 친절하게 내 편집을 확인하십시오. 나는 기본 확인() 메소드처럼 원한다. – Bhushan

+0

return true 대신 경고 메시지를 내고 false를 리턴한다. –

0

콜백 기능을 사용해야합니다. 당신은 성공 분야를 본다? 이것은 jquery msgBox 웹 사이트에서 온 것입니다.

$.msgBox({ 
    title: "Are You Sure", 
    content: "Would you like a cup of coffee?", 
    type: "confirm", 
    buttons: [{ value: "Yes" }, { value: "No" }, { value: "Cancel"}], 
    success: function (result) { 
     if (result == "Yes") { 
      alert("One cup of coffee coming right up!"); 
     } 
    } 
}); 
+0

감사합니다 lombausch !! 친절하게 내 편집을 확인하십시오. 기본 확인() 메소드처럼 원합니다. – Bhushan

관련 문제