如何在打开警报bi = ox时关闭jquery对话框

问题描述 投票:0回答:2

我下面有一个JavaScript代码:

var alertText = "Hey.";
       $("div").remove("#confirmationDialogBox");
       $(document.body).append("<div id='confirmationDialogBox'></div>");
       $("#confirmationDialogBox").html('');
       $("#confirmationDialogBox").dialog({
           resizable: false,
           height: 140,
           title: 'Alert !!',
           modal: true,
           draggable: false,
           zIndex: 99999,
           buttons: [{
               "class": 'btnModalDisplay',
               text: "Ok",
               click: function () {
                   //Calls another function that shows an alert
               }}]
       }).text(alertText);

我的问题是,当对话框出现并且单击对话框的“确定”时,我必须调用另一个显示警报的函数。但是由于某些原因,当我单击“确定”时,对话框没有关闭并显示警报。有人可以帮助我如何关闭对话框,然后显示警报?

javascript jquery grails grails-3.0
2个回答
0
投票

尝试一下:

var alertText = "Hey.";
   $("div").remove("#confirmationDialogBox");
   $(document.body).append("<div id='confirmationDialogBox'></div>");
   $("#confirmationDialogBox").html('');
   $("#confirmationDialogBox").dialog({
       resizable: false,
       height: 140,
       title: 'Alert !!',
       modal: true,
       draggable: false,
       zIndex: 99999,
       buttons: [{
           "class": 'btnModalDisplay',
           text: "Ok",
           click: function () {
               //Calls another function that shows an alert
           $( this ).dialog( "close" );                      /// add this line to close dialog
           }}]
   }).text(alertText);

0
投票

您可以尝试像这样更新点击事件:

$("#confirmationDialogBox").dialog({
  ...
  buttons: [{
    "class": 'btnModalDisplay',
    text: "Ok",
    click: function(e) {
      //Calls another function that shows an alert
      e.preventDefault();
      $('#confirmationDialogBox').dialog('close');
    }
  }]
});
© www.soinside.com 2019 - 2024. All rights reserved.