2014-09-05 68 views
0

我想在用戶點擊下面模式中的「取消」按鈕時添加提示。 它會提示他們確認該操作。下面的代碼是我目前嘗試的。確認模式按鈕的動作asp.net

function ShowAddEditExecutive() { 
     $("#addEditExecutive").dialog({ 
      modal: true, 
      width: 800, 
      appendTo: "form", 
      open: function() { 
       $(this).dialog("widget").find(".ui-dialog-titlebar").show(); 
       // Removes the do you want to leave this page dialog. 
       window.onbeforeunload = null; 
       // The two isplalines below are 2 different ways to ensure the 
       // background is completely grayed out if the modal is larger 
       // then the page. The first was chosen so that the scroll 
       // bars are not disabled. 
       $('.ui-widget-overlay').css('position', 'fixed'); 
       //$('body').css('overflow', 'hidden'); 
      }, 
      buttons: { 
       "Add/Edit Executive Information": function() { 
        $("[id*=btnAddEditExecutive]").click(); 
       }, 
       "Cancel": function() { 

        $(this).dialog("close"); 

       } 
      }, 
     close: function (ev, ui) { 
      // Ensures when you cancel that the values are not retained. 
      $(this).remove(); 
      // The two lines below are 2 different ways to ensure the 
      // background is completely grayed out if the modal is larger 
      // then the page. The first was chosen so that the scroll 
      // bars are not disabled. 
      $('.ui-widget-overlay').css('position', 'absolute'); 
      //$('body').css('overflow', 'inline'); 
     }, 

    }); 


    } 
+0

代碼有什麼問題? – Kyojimaru 2014-09-05 16:37:39

+0

這段代碼沒有問題,我試圖讓「取消」按鈕產生一個確認窗口。 – 2014-09-05 16:58:53

回答

0

,如果你想創建一個原生的方式來確認操作,您可以使用confirm來提示用戶選擇繼續與否,這裏就是你應該在你的代碼做

"Cancel": function() { 
    if(confirm("Are you sure you want to cancel ?")) 
    { 
     //code if yes 
     $(this).dialog("close"); 
    } 
    else 
    { 
     //code if no, don't do anything in your case, or don't use the else 
    } 
} 

這裏的usage example

,如果你想使它看起來相同與你的設計的另一種方式,你可以創建一個自定義<div>其中包含的用戶是否同意確認文本或希望使用CSS,並使用繼續與否,然後stylejQuery onclick function來處理事件。

+0

你先生是聖人。謝謝 – 2014-09-05 17:20:00