jquery如何让这个对话框的“确定”按钮工作

jquery how to get this dialog Ok button to work?

本文关键字:确定 按钮 工作 对话框 jquery      更新时间:2023-09-26

对话框显示出来,并且运行良好。右上角的"X"关闭按钮正确地关闭对话框,但"确定"按钮不起任何作用。(我使用的是jquery 1.9.1)

  function showFollowProjectInDialog(followurl){
      $.ajax({
        url: followurl,
        success: function(data) {
          $("#TFdialog").html(data).dialog({
            resizable: true,
            height: 600,
            width: 700,
            modal:true,
            buttons: {
            Ok: function() {$( "#TFdialog" ).dialog( "close" );}
            },
            }).dialog('open');
        }
      });
    }

我也试过不在按钮后面加逗号,比如:

buttons: {
    Ok: function() {$( "#TFdialog" ).dialog( "close" );}
        }
}).dialog('open');

我试过这些:

buttons: [{
            text: "Ok",
            Click : function () {
                $("#TFdialog").dialog("close");
            }
        }]

和:

buttons: [{
 Ok: function() {
     $("#TFdialog").dialog("close");
 }
}]

我试着用类似的"this"替换"#TFdialog"

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

尝试进行

    buttons: [
    {
        text: "Ok",
        click: function() {
          $( this ).dialog( 'close' );
          // your code goes here
        }
      }
    ]

假设您使用jQuery UI引用https://jqueryui.com/dialog/#modal-形成

buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }

您也可以将对话框用作对象:

var myDialog;
myDialog = $("#TFdialog").html(data).dialog({
            resizable: true,
            autoOpen: false,// added this
            height: 600,
            width: 700,
            modal:true,
            buttons: {
               Ok: function() {
                  myDialog.dialog( "close" );
                  },
              "Close this Soon" : DelayClose,
            }
            });
myDialog.dialog('open');
function DelayClose(){
   setTimeout(function() {
    myDialog.dialog( "close" );
  }, 500 );
}

为什么要为您的对象使用对象的示例:

var myDialog;
myDialog = $("#TFdialog").dialog({
            resizable: true,
            autoOpen: false,// added this
            height: 600,
            width: 700,
            modal:true,
            buttons: {
               Ok: function() {
                  myDialog.dialog( "close" );
                  }
            }
            });
function showFollowProjectInDialog(followurl){
    $.ajax({
        url: followurl
    }).done(function(data){
        $("#TFdialog").html(data);
        myDialog.dialog('open');
    });
}