2011-10-15 41 views
0

jQuery UI主題不錯,它們適用於整個文檔,但我有一些情況下,必須更改標題欄顏色等對話框的樣式。jQueryUI.dialog:重寫單個CSS樣式屬性?

以我jQuery的用戶界面的CSS,標題欄是編碼:

的.ui-對話框的.ui-對話框的標題欄{填充:.4em 1em的;位置:相對; }

這裏是我的javascript:

var $AlertDialog = $('<div"></div>') 
.dialog({ 
    autoOpen: false, 
    title: 'Alert Message', 
    buttons: {Ok: function() {$(this).dialog("close");}} 
});  

function Alerter(cTxt) 
{ 
    $AlertDialog.html(cTxt); 
    $AlertDialog.css('ui-dialog-titlebar','color: red'); 
    $AlertDialog.dialog('open'); 
}; 

警報器(),然後調用作爲警報的替代品()。

訪問和更改'ui-dialog-titlebar'的顏色屬性不起作用。

在這個問題之前有大量的閱讀。似乎其他人也有類似的問題,但不特定於jQuery UI。

這怎麼辦?


更新:

多虧了一個很好的提示,我這樣做:

$AlertDialog.dialog('open'); 
$("#.ui-dialog .ui-dialog-title").css('color','red'); 
$("#.ui-dialog .ui-dialog-title").css('background-color','orange'); 

作品。但可接受的做法?

+1

爲什麼不添加一個類並使用CSS設計它? – meleyal

回答

0

首先,

根據documentation的CSS()採用屬性作爲PARAM。
看來你正在嘗試改變ui-dialog-titlebar。而是試試這個:

... 
function Alerter(cTxt) 
{ 
    $AlertDialog.html(cTxt); 
    $AlertDialog.dialog('open'); 
    $(".ui-dialog .ui-dialog-title").css('color','red'); 
    $(".ui-dialog .ui-dialog-title").css('background-color','orange'); 
    //Assuming you want to change header color only 
    //see the theming structure at http://jqueryui.com/demos/dialog/#theming 
}; 
+0

$ moguzalp您提供了一個很好的提示。使用> span產生了一個錯誤,但我以另一種方式得到了它。 –

+0

$ AlertDialog.dialog('open'); (「#。ui-dialog .ui-dialog-title」).css('color','red'); (「#。ui-dialog .ui-dialog-title」).css('background-color','orange'); –

1

我的建議是不使用.ui-對話框選擇器,因爲頁面上可能有多個對話框。你可以遍歷標題欄。

... 
    $AlertDialog.html(cTxt); 
    // might as well use the theme since its part of jquery ui 
    $AlertDialog.prev().addClass("ui-state-error"); 
    $AlertDialog.dialog('open');