如何将jquery对话框的位置更改为中心

How to change the position of jquery dialog box into center?

本文关键字:位置 为中心 对话框 jquery      更新时间:2023-09-26

我有一个jquery对话框,我在其中显示div的内容。但问题是,每当单击链接按钮时,对话框就会出现在页面底部,因为链接按钮也在页面底部。但我希望它出现在页面顶部,这样用户就不必向下滚动来找到对话框。

这是我的aspx代码:

  <a href="#" onclick="OpenDialog('#divNominees','Add Nominee')">

Jquery代码:

   function OpenDialog(obj,title) {
    $(obj).dialog({ title: title, modal: true })
    $(obj).parent().appendTo($("form:first"));
    var p = $(obj).parent();
  }

如果有人帮我解决这个问题,我将不胜感激,因为我已经浪费了一上午的时间来解决这个问题。

提前谢谢。

您可以保持您的div不与其他表/div或其他表嵌套。在下面的示例中,tblOuter是我希望对话框居中的表的id。

 $("#divNominees'").dialog({
             modal: true,
             position: { my: "center", at: "center", of: $("#tblOuter") },
             title: "Nominees",
             dialogClass: "ui-dialog-content"
         });
once try with add css 
margin:0 auto; 
or only auto.

读取文档

$('my-selector').dialog('option', 'position', 'center');