2010-05-25 27 views
2

我有一個jQuery對話框,可以正確顯示並響應按鈕點擊。不幸的是,儘管我試圖說服它,但它始終位於瀏覽器窗口中的0,0處。有任何想法嗎?以對話框爲中心的jQuery UI問題

var $dialog = $('<div></div>') 
    .html('my message') 
     .dialog({ autoOpen: false, title: 'my title', position: 'center', bgiframe: true 
     }); 

    $dialog.dialog('option', 'buttons', buttons); 
    $dialog.dialog('option', 'position', "center"); 
    $dialog.dialog("open"); 

回答

3

如果它不是自動居中,那麼在文檔標記中出現錯誤(缺少關閉標記通常是罪魁禍首)。

http://jsbin.com/uhago4/edit

1

jQuery使用該對話框的寬度使其居中。如果它還沒有顯示,附加到DOM,或創建一個固定的寬度,那麼它沒有寬度,不能居中正確。

要解決,只是中心開業後:

var $dialog = $('<div></div>') 
.html('my message') 
.dialog({ autoOpen: false, title: 'my title', position: 'center', bgiframe: true 
    }); 

$dialog.dialog('option', 'buttons', buttons); 
$dialog.dialog("open"); 
$dialog.dialog('option', 'position', "center"); 
2

我有同樣的問題。

我不知道如何把我的jquery對話框居中。
我已經嘗試了很多方法。
沒有爲我工作。

但最後我找到了解決辦法,我的解決辦法是

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
+1

同時使用HTML5: <!DOCTYPE html> – 2013-03-25 13:00:22

+0

對於任何使用DNN和獲得未經審查模式的人:我在使用DotNetNuke(使用jQuery UI)時遇到了這個問題。這正是問題所在,我部署的皮膚需要附帶的[template] .doctype.xml文件以及未使用我的皮膚部署的doctype聲明。一旦我部署了doctype聲明,模式再次開始集中。 – 2014-05-21 18:39:39

0

刪除position: 'center'爲我工作。諷刺的權利?