2013-10-11 26 views
0

我是新來的jQuery.I使用自定義消息框。我已經使用jQuery.msgBox()同步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

給予警報消息,而不是返回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