2014-03-25 53 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"); 
       } 
      } 
     }); 

現在它填充的內容之前,顯示它的對話框,因此允許其正常中心本身。