2012-04-23 38 views
4

我使用了一個簡單的JavaScript確認函數,該函數被我的Asp.net項目中的所有頁面使用,並且我想將其替換爲jQuery確認對話框。 我使用Apprise jQuery確認對話框庫。 但jQuery的異步工作確認對話框導致問題。 讓我給你我的項目的一些代碼示例..如何使用異步JQuery確認對話框作爲同步?

這是我的老JavaScript的confirm功能

function confirmForOperation(message) { 
    if (confirm(message) == true) 
     return true; 
    else 
     return false; 
} 

這是我的新的異步jQuery的確認對話框功能

function confirmForOperation(message) { 
    apprise(message, { 'verify': true, 'animate': true, 'textYes': 'Yes', 'textNo': 'No' }, 
    function (r) { 
     if (r) { 
      // User clicked YES.. 
      return true; 
     } 
     else { 
      // User clicked NO.. 
      return false; 
     } 
    }); 
} 

您可以提供我使用以下功能作爲

function confirmForOperation(message, callBack) { 
    apprise(message, { 'verify': true, 'animate': true, 'textYes': 'Yes', 'textNo': 'No' }, 
    function (r) { 
     if (r) { 
      // User clicked YES.. 

      if ($.isFunction(callback)) { 
       callback.apply(); 
      } 
     } 
     else { 
      // User clicked NO.. 
      return false; 
     } 
    }); 
} 

但回調機制不適合我,因爲該地區(代碼)我用這個確認對話框的功能之一是如下:

<asp:Button ID="btnDelete" runat="server" CausesValidation="false" CommandName="Delete" 
Text="<%$ Resources:BTNResource, BUTTON_DELETE_LABEL %>" OnClientClick="return confirmForOperation();" /> 

任何想法?

回答