2014-03-25 52 views
0

我有一个jQuery UI对话框,当有表单错误时显示。jQuery UI对话框中动态内容没有居中正确

继承人的代码:

function alert_field_errors (errors) 
{ 
    $('<div></div>').dialog({ 
     modal: true, 
     title: "Error", 
     open: function() { 
      $(this).html('The following are required:<br /><br />'+errors+'<br />Please complete these in order to continue.'); 
     }, 
     buttons: { 
      Ok: function() { 
       $(this).dialog("close"); 
      } 
     } 
    }); 
} 

errors变量将包含类似First Name<br />Last Name<br />Email Address<br />

它的伟大工程,除了一个事实,即它不居中。它似乎在加载内容之前定位自己,以便在显示时,对话框的底部边距与对话框的顶部边距相比更靠近窗口的底部。

我试过使用position选项,但似乎没有任何工作。

任何帮助将不胜感激。

回答

0

继承人我如何固定它:

我创建的error-dialog标识网页上的空div并赋予它的CSS display: none;

然后,我改变了我的代码如下:

 $('#error-dialog').html('The following are required:<br /><br /><i>'+$errors+'</i><br />Please complete these in order to continue.'); 
     $('#error-dialog').dialog({ 
      modal: true, 
      title: "Error", 
      buttons: { 
       Ok: function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 

现在它填充的内容之前,显示它的对话框,因此允许其正常中心本身。