2014-09-05 70 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